src/api-impl: fix up code style, mainly for code imported from AOSP

used the following (plus manual edits):
`clang-format --style="{BasedOnStyle: LLVM, IndentWidth: 8, UseTab: Always, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: true, ColumnLimit: 0}`
This commit is contained in:
Mis012
2023-06-22 11:45:46 +02:00
parent 824b821f5a
commit 0a9591c474
208 changed files with 154568 additions and 150150 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -26,239 +26,241 @@ import java.lang.reflect.Array;
* ArrayUtils contains some methods that you can call to find out
* the most efficient increments by which to grow arrays.
*/
public class ArrayUtils
{
private static Object[] EMPTY = new Object[0];
private static final int CACHE_SIZE = 73;
private static Object[] sCache = new Object[CACHE_SIZE];
public class ArrayUtils {
private static Object[] EMPTY = new Object[0];
private static final int CACHE_SIZE = 73;
private static Object[] sCache = new Object[CACHE_SIZE];
private ArrayUtils() { /* cannot be instantiated */ }
private ArrayUtils() { /* cannot be instantiated */
}
public static int idealByteArraySize(int need) {
for (int i = 4; i < 32; i++)
if (need <= (1 << i) - 12)
return (1 << i) - 12;
public static int idealByteArraySize(int need) {
for (int i = 4; i < 32; i++)
if (need <= (1 << i) - 12)
return (1 << i) - 12;
return need;
}
return need;
}
public static int idealBooleanArraySize(int need) {
return idealByteArraySize(need);
}
public static int idealBooleanArraySize(int need) {
return idealByteArraySize(need);
}
public static int idealShortArraySize(int need) {
return idealByteArraySize(need * 2) / 2;
}
public static int idealShortArraySize(int need) {
return idealByteArraySize(need * 2) / 2;
}
public static int idealCharArraySize(int need) {
return idealByteArraySize(need * 2) / 2;
}
public static int idealCharArraySize(int need) {
return idealByteArraySize(need * 2) / 2;
}
public static int idealIntArraySize(int need) {
return idealByteArraySize(need * 4) / 4;
}
public static int idealIntArraySize(int need) {
return idealByteArraySize(need * 4) / 4;
}
public static int idealFloatArraySize(int need) {
return idealByteArraySize(need * 4) / 4;
}
public static int idealFloatArraySize(int need) {
return idealByteArraySize(need * 4) / 4;
}
public static int idealObjectArraySize(int need) {
return idealByteArraySize(need * 4) / 4;
}
public static int idealObjectArraySize(int need) {
return idealByteArraySize(need * 4) / 4;
}
public static int idealLongArraySize(int need) {
return idealByteArraySize(need * 8) / 8;
}
public static int idealLongArraySize(int need) {
return idealByteArraySize(need * 8) / 8;
}
/**
* Checks if the beginnings of two byte arrays are equal.
*
* @param array1 the first byte array
* @param array2 the second byte array
* @param length the number of bytes to check
* @return true if they're equal, false otherwise
*/
public static boolean equals(byte[] array1, byte[] array2, int length) {
if (length < 0) {
throw new IllegalArgumentException();
}
/**
* Checks if the beginnings of two byte arrays are equal.
*
* @param array1 the first byte array
* @param array2 the second byte array
* @param length the number of bytes to check
* @return true if they're equal, false otherwise
*/
public static boolean equals(byte[] array1, byte[] array2, int length) {
if (length < 0) {
throw new IllegalArgumentException();
}
if (array1 == array2) {
return true;
}
if (array1 == null || array2 == null || array1.length < length || array2.length < length) {
return false;
}
for (int i = 0; i < length; i++) {
if (array1[i] != array2[i]) {
return false;
}
}
return true;
}
if (array1 == array2) {
return true;
}
if (array1 == null || array2 == null || array1.length < length || array2.length < length) {
return false;
}
for (int i = 0; i < length; i++) {
if (array1[i] != array2[i]) {
return false;
}
}
return true;
}
/**
* Returns an empty array of the specified type. The intent is that
* it will return the same empty array every time to avoid reallocation,
* although this is not guaranteed.
*/
public static <T> T[] emptyArray(Class<T> kind) {
if (kind == Object.class) {
return (T[]) EMPTY;
}
/**
* Returns an empty array of the specified type. The intent is that
* it will return the same empty array every time to avoid reallocation,
* although this is not guaranteed.
*/
public static <T> T[] emptyArray(Class<T> kind) {
if (kind == Object.class) {
return (T[])EMPTY;
}
int bucket = ((System.identityHashCode(kind) / 8) & 0x7FFFFFFF) % CACHE_SIZE;
Object cache = sCache[bucket];
int bucket = ((System.identityHashCode(kind) / 8) & 0x7FFFFFFF) % CACHE_SIZE;
Object cache = sCache[bucket];
if (cache == null || cache.getClass().getComponentType() != kind) {
cache = Array.newInstance(kind, 0);
sCache[bucket] = cache;
if (cache == null || cache.getClass().getComponentType() != kind) {
cache = Array.newInstance(kind, 0);
sCache[bucket] = cache;
// Log.e("cache", "new empty " + kind.getName() + " at " + bucket);
}
// Log.e("cache", "new empty " + kind.getName() + " at " + bucket);
}
return (T[]) cache;
}
return (T[])cache;
}
/**
* Checks that value is present as at least one of the elements of the array.
* @param array the array to check in
* @param value the value to check for
* @return true if the value is present in the array
*/
public static <T> boolean contains(T[] array, T value) {
return indexOf(array, value) != -1;
}
/**
* Checks that value is present as at least one of the elements of the array.
* @param array the array to check in
* @param value the value to check for
* @return true if the value is present in the array
*/
public static <T> boolean contains(T[] array, T value) {
return indexOf(array, value) != -1;
}
/**
* Return first index of {@code value} in {@code array}, or {@code -1} if
* not found.
*/
public static <T> int indexOf(T[] array, T value) {
for (int i = 0; i < array.length; i++) {
if (array[i] == null) {
if (value == null) return i;
} else {
if (value != null && array[i].equals(value)) return i;
}
}
return -1;
}
/**
* Return first index of {@code value} in {@code array}, or {@code -1} if
* not found.
*/
public static <T> int indexOf(T[] array, T value) {
for (int i = 0; i < array.length; i++) {
if (array[i] == null) {
if (value == null)
return i;
} else {
if (value != null && array[i].equals(value))
return i;
}
}
return -1;
}
/**
* Test if all {@code check} items are contained in {@code array}.
*/
public static <T> boolean containsAll(T[] array, T[] check) {
for (T checkItem : check) {
if (!contains(array, checkItem)) {
return false;
}
}
return true;
}
/**
* Test if all {@code check} items are contained in {@code array}.
*/
public static <T> boolean containsAll(T[] array, T[] check) {
for (T checkItem : check) {
if (!contains(array, checkItem)) {
return false;
}
}
return true;
}
public static boolean contains(int[] array, int value) {
for (int element : array) {
if (element == value) {
return true;
}
}
return false;
}
public static boolean contains(int[] array, int value) {
for (int element : array) {
if (element == value) {
return true;
}
}
return false;
}
public static long total(long[] array) {
long total = 0;
for (long value : array) {
total += value;
}
return total;
}
public static long total(long[] array) {
long total = 0;
for (long value : array) {
total += value;
}
return total;
}
/**
* Appends an element to a copy of the array and returns the copy.
* @param array The original array, or null to represent an empty array.
* @param element The element to add.
* @return A new array that contains all of the elements of the original array
* with the specified element added at the end.
*/
@SuppressWarnings("unchecked")
public static <T> T[] appendElement(Class<T> kind, T[] array, T element) {
final T[] result;
final int end;
if (array != null) {
end = array.length;
result = (T[])Array.newInstance(kind, end + 1);
System.arraycopy(array, 0, result, 0, end);
} else {
end = 0;
result = (T[])Array.newInstance(kind, 1);
}
result[end] = element;
return result;
}
/**
* Appends an element to a copy of the array and returns the copy.
* @param array The original array, or null to represent an empty array.
* @param element The element to add.
* @return A new array that contains all of the elements of the original array
* with the specified element added at the end.
*/
@SuppressWarnings("unchecked")
public static <T> T[] appendElement(Class<T> kind, T[] array, T element) {
final T[] result;
final int end;
if (array != null) {
end = array.length;
result = (T[])Array.newInstance(kind, end + 1);
System.arraycopy(array, 0, result, 0, end);
} else {
end = 0;
result = (T[])Array.newInstance(kind, 1);
}
result[end] = element;
return result;
}
/**
* Removes an element from a copy of the array and returns the copy.
* If the element is not present, then the original array is returned unmodified.
* @param array The original array, or null to represent an empty array.
* @param element The element to remove.
* @return A new array that contains all of the elements of the original array
* except the first copy of the specified element removed. If the specified element
* was not present, then returns the original array. Returns null if the result
* would be an empty array.
*/
@SuppressWarnings("unchecked")
public static <T> T[] removeElement(Class<T> kind, T[] array, T element) {
if (array != null) {
final int length = array.length;
for (int i = 0; i < length; i++) {
if (array[i] == element) {
if (length == 1) {
return null;
}
T[] result = (T[])Array.newInstance(kind, length - 1);
System.arraycopy(array, 0, result, 0, i);
System.arraycopy(array, i + 1, result, i, length - i - 1);
return result;
}
}
}
return array;
}
/**
* Removes an element from a copy of the array and returns the copy.
* If the element is not present, then the original array is returned unmodified.
* @param array The original array, or null to represent an empty array.
* @param element The element to remove.
* @return A new array that contains all of the elements of the original array
* except the first copy of the specified element removed. If the specified element
* was not present, then returns the original array. Returns null if the result
* would be an empty array.
*/
@SuppressWarnings("unchecked")
public static <T> T[] removeElement(Class<T> kind, T[] array, T element) {
if (array != null) {
final int length = array.length;
for (int i = 0; i < length; i++) {
if (array[i] == element) {
if (length == 1) {
return null;
}
T[] result = (T[])Array.newInstance(kind, length - 1);
System.arraycopy(array, 0, result, 0, i);
System.arraycopy(array, i + 1, result, i, length - i - 1);
return result;
}
}
}
return array;
}
public static int[] appendInt(int[] cur, int val) {
if (cur == null) {
return new int[] { val };
}
final int N = cur.length;
for (int i = 0; i < N; i++) {
if (cur[i] == val) {
return cur;
}
}
int[] ret = new int[N + 1];
System.arraycopy(cur, 0, ret, 0, N);
ret[N] = val;
return ret;
}
public static int[] appendInt(int[] cur, int val) {
if (cur == null) {
return new int[] {val};
}
final int N = cur.length;
for (int i = 0; i < N; i++) {
if (cur[i] == val) {
return cur;
}
}
int[] ret = new int[N + 1];
System.arraycopy(cur, 0, ret, 0, N);
ret[N] = val;
return ret;
}
public static int[] removeInt(int[] cur, int val) {
if (cur == null) {
return null;
}
final int N = cur.length;
for (int i = 0; i < N; i++) {
if (cur[i] == val) {
int[] ret = new int[N - 1];
if (i > 0) {
System.arraycopy(cur, 0, ret, 0, i);
}
if (i < (N - 1)) {
System.arraycopy(cur, i + 1, ret, i, N - i - 1);
}
return ret;
}
}
return cur;
}
public static int[] removeInt(int[] cur, int val) {
if (cur == null) {
return null;
}
final int N = cur.length;
for (int i = 0; i < N; i++) {
if (cur[i] == val) {
int[] ret = new int[N - 1];
if (i > 0) {
System.arraycopy(cur, 0, ret, 0, i);
}
if (i < (N - 1)) {
System.arraycopy(cur, i + 1, ret, i, N - i - 1);
}
return ret;
}
}
return cur;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -15,20 +15,20 @@ public class EGLImpl implements EGL10 {
private native boolean native_eglChooseConfig(long egl_display, int[] attrib_list, long[] egl_configs, int config_size, int[] num_config);
public boolean eglChooseConfig(EGLDisplay display, int[] attrib_list, EGLConfig[] configs, int config_size, int[] num_config) {
public boolean eglChooseConfig(EGLDisplay display, int[] attrib_list, EGLConfig[] configs, int config_size, int[] num_config) {
long[] native_egl_configs = null;
if(config_size != 0) {
if(configs == null) {
throw new java.lang.IllegalArgumentException("app error: eglChooseConfig called with non-zero 'config_size' ("+config_size+"), but with null 'configs' array");
if (config_size != 0) {
if (configs == null) {
throw new java.lang.IllegalArgumentException("app error: eglChooseConfig called with non-zero 'config_size' (" + config_size + "), but with null 'configs' array");
}
native_egl_configs = new long[config_size];
}
boolean ret = native_eglChooseConfig(display.native_egl_display, attrib_list, native_egl_configs, config_size, num_config);
if(configs != null) {
for(int i = 0; i < configs.length; i++) {
if (configs != null) {
for (int i = 0; i < configs.length; i++) {
configs[i] = new EGLConfig(native_egl_configs[i]);
}
}
@@ -36,29 +36,30 @@ public class EGLImpl implements EGL10 {
return ret;
}
public boolean eglCopyBuffers(EGLDisplay display, EGLSurface surface, Object native_pixmap) { return false; }
public EGLSurface eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list) { return null; }
public EGLSurface eglCreatePixmapSurface(EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list) { return null; }
public EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list) { return null; }
public boolean eglDestroyContext(EGLDisplay display, EGLContext context) { return false; }
public boolean eglDestroySurface(EGLDisplay display, EGLSurface surface) { return false; }
public boolean eglGetConfigAttrib(EGLDisplay display, EGLConfig config, int attribute, int[] value) { return false; }
public boolean eglGetConfigs(EGLDisplay display, EGLConfig[] configs, int config_size, int[] num_config) { return false; }
public EGLContext eglGetCurrentContext() { return null; }
public EGLDisplay eglGetCurrentDisplay() { return null; }
public EGLSurface eglGetCurrentSurface(int readdraw) { return null; }
public EGLDisplay eglGetDisplay(Object native_display) { return null; }
public int eglGetError() { return EGL_SUCCESS; } // don't let yourself get fooled, this is also a stub :P
public boolean eglInitialize(EGLDisplay display, int[] major_minor) { return false; }
public boolean eglMakeCurrent(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext context) { return false; }
public boolean eglQueryContext(EGLDisplay display, EGLContext context, int attribute, int[] value) { return false; }
public String eglQueryString(EGLDisplay display, int name) { return "FIXME"; }
public boolean eglQuerySurface(EGLDisplay display, EGLSurface surface, int attribute, int[] value) { return false; }
/** @hide **/
public boolean eglReleaseThread() { return false; }
public boolean eglSwapBuffers(EGLDisplay display, EGLSurface surface) { return false; }
public boolean eglTerminate(EGLDisplay display) { return false; }
public boolean eglWaitGL() { return false; }
public boolean eglWaitNative(int engine, Object bindTarget) { return false; }
public boolean eglCopyBuffers(EGLDisplay display, EGLSurface surface, Object native_pixmap) { return false; }
public EGLSurface eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, int[] attrib_list) { return null; }
public EGLSurface eglCreatePixmapSurface(EGLDisplay display, EGLConfig config, Object native_pixmap, int[] attrib_list) { return null; }
public EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, Object native_window, int[] attrib_list) { return null; }
public boolean eglDestroyContext(EGLDisplay display, EGLContext context) { return false; }
public boolean eglDestroySurface(EGLDisplay display, EGLSurface surface) { return false; }
public boolean eglGetConfigAttrib(EGLDisplay display, EGLConfig config, int attribute, int[] value) { return false; }
public boolean eglGetConfigs(EGLDisplay display, EGLConfig[] configs, int config_size, int[] num_config) { return false; }
public EGLContext eglGetCurrentContext() { return null; }
public EGLDisplay eglGetCurrentDisplay() { return null; }
public EGLSurface eglGetCurrentSurface(int readdraw) { return null; }
public EGLDisplay eglGetDisplay(Object native_display) { return null; }
public int eglGetError() { return EGL_SUCCESS; } // don't let yourself get fooled, this is also a stub :P
public boolean eglInitialize(EGLDisplay display, int[] major_minor) { return false; }
public boolean eglMakeCurrent(EGLDisplay display, EGLSurface draw, EGLSurface read, EGLContext context) { return false; }
public boolean eglQueryContext(EGLDisplay display, EGLContext context, int attribute, int[] value) { return false; }
public String eglQueryString(EGLDisplay display, int name) { return "FIXME"; }
public boolean eglQuerySurface(EGLDisplay display, EGLSurface surface, int attribute, int[] value) { return false; }
/**
* @hide *
*/
public boolean eglReleaseThread() { return false; }
public boolean eglSwapBuffers(EGLDisplay display, EGLSurface surface) { return false; }
public boolean eglTerminate(EGLDisplay display) { return false; }
public boolean eglWaitGL() { return false; }
public boolean eglWaitNative(int engine, Object bindTarget) { return false; }
}

File diff suppressed because it is too large Load Diff

View File

@@ -3,13 +3,13 @@ package com.google.android.vending.licensing;
import android.content.Context;
public class LicenseChecker {
public LicenseChecker(Context context, Policy policy, String encodedPublicKey) {
public LicenseChecker(Context context, Policy policy, String encodedPublicKey) {
// TODO: do something here?
}
}
public synchronized void checkAccess(LicenseCheckerCallback callback) {
// this is not ideal, but it doesn't make sense to spend much effort on doing this "properly" when the effort required to bypass this doesn't scale with the effort spent by us
// also, it might not be possible to do this "properly" without having the real google play store in the equation, which is not desirable for a multitude of reasons...
callback.allow(0x0100/*Policy.LICENSED*/);
callback.allow(0x0100 /*Policy.LICENSED*/);
}
}

View File

@@ -34,35 +34,36 @@ package com.google.android.vending.licensing;
*/
public interface LicenseCheckerCallback {
/**
* Allow use. App should proceed as normal.
*
* @param reason Policy.LICENSED or Policy.RETRY typically. (although in
* theory the policy can return Policy.NOT_LICENSED here as well)
*/
public void allow(int reason);
/**
* Allow use. App should proceed as normal.
*
* @param reason Policy.LICENSED or Policy.RETRY typically. (although in
* theory the policy can return Policy.NOT_LICENSED here as well)
*/
public void allow(int reason);
/**
* Don't allow use. App should inform user and take appropriate action.
*
* @param reason Policy.NOT_LICENSED or Policy.RETRY. (although in theory
* the policy can return Policy.LICENSED here as well ---
* perhaps the call to the LVL took too long, for example)
*/
public void dontAllow(int reason);
/**
* Don't allow use. App should inform user and take appropriate action.
*
* @param reason Policy.NOT_LICENSED or Policy.RETRY. (although in theory
* the policy can return Policy.LICENSED here as well ---
* perhaps the call to the LVL took too long, for example)
*/
public void dontAllow(int reason);
/** Application error codes. */
public static final int ERROR_INVALID_PACKAGE_NAME = 1;
public static final int ERROR_NON_MATCHING_UID = 2;
public static final int ERROR_NOT_MARKET_MANAGED = 3;
public static final int ERROR_CHECK_IN_PROGRESS = 4;
public static final int ERROR_INVALID_PUBLIC_KEY = 5;
public static final int ERROR_MISSING_PERMISSION = 6;
/**
* Application error codes.
*/
public static final int ERROR_INVALID_PACKAGE_NAME = 1;
public static final int ERROR_NON_MATCHING_UID = 2;
public static final int ERROR_NOT_MARKET_MANAGED = 3;
public static final int ERROR_CHECK_IN_PROGRESS = 4;
public static final int ERROR_INVALID_PUBLIC_KEY = 5;
public static final int ERROR_MISSING_PERMISSION = 6;
/**
* Error in application code. Caller did not call or set up license checker
* correctly. Should be considered fatal.
*/
public void applicationError(int errorCode);
/**
* Error in application code. Caller did not call or set up license checker
* correctly. Should be considered fatal.
*/
public void applicationError(int errorCode);
}

View File

@@ -1,5 +1,4 @@
package com.google.android.vending.licensing;
public interface Policy {
}