a little cleanup
This commit is contained in:
parent
2c443515c0
commit
13386dd177
18 changed files with 84 additions and 355 deletions
|
|
@ -18,12 +18,8 @@ package com.google.android.gms.common.data;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.ContentValues;
|
||||
import android.database.AbstractWindowedCursor;
|
||||
import android.database.CharArrayBuffer;
|
||||
import android.database.Cursor;
|
||||
import android.database.CursorWindow;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
|
||||
|
|
@ -45,9 +41,6 @@ import java.util.Map;
|
|||
*/
|
||||
@PublicApi(until = "1")
|
||||
public class DataHolder extends AutoSafeParcelable implements Closeable {
|
||||
@SafeParceled(1000)
|
||||
private final int versionCode = 1;
|
||||
|
||||
@SafeParceled(1)
|
||||
private final String[] columns;
|
||||
|
||||
|
|
@ -69,13 +62,6 @@ public class DataHolder extends AutoSafeParcelable implements Closeable {
|
|||
protected static final int FIELD_TYPE_STRING = 3;
|
||||
protected static final int FIELD_TYPE_BLOB = 4;
|
||||
|
||||
private DataHolder() {
|
||||
columns = null;
|
||||
windows = null;
|
||||
statusCode = 0;
|
||||
metadata = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a data holder with the specified data.
|
||||
*
|
||||
|
|
@ -92,17 +78,6 @@ public class DataHolder extends AutoSafeParcelable implements Closeable {
|
|||
validateContents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a data holder wrapping the provided cursor, with provided status code and metadata.
|
||||
*
|
||||
* @param cursor The cursor containing the data.
|
||||
* @param statusCode The status code of this {@link DataHolder}.
|
||||
* @param metadata The metadata associated with this {@link DataHolder} (may be null).
|
||||
*/
|
||||
public DataHolder(AbstractWindowedCursor cursor, int statusCode, Bundle metadata) {
|
||||
this(cursor.getColumnNames(), createCursorWindows(cursor), statusCode, metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a data holder wrapping the provided cursor, with provided status code and metadata.
|
||||
*
|
||||
|
|
@ -135,48 +110,10 @@ public class DataHolder extends AutoSafeParcelable implements Closeable {
|
|||
return builder(columns, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param statusCode The status code of this {@link DataHolder}.
|
||||
* @param metadata The metadata associated with this {@link DataHolder} (may be null).
|
||||
* @return An empty {@link DataHolder} object with the given status and metadata.
|
||||
*/
|
||||
public static DataHolder empty(int statusCode, Bundle metadata) {
|
||||
return new DataHolder(new String[0], new CursorWindow[0], statusCode, metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param statusCode The status code of this {@link DataHolder}.
|
||||
* @return An empty {@link DataHolder} object with the given status and null metadata.
|
||||
*/
|
||||
public static DataHolder empty(int statusCode) {
|
||||
return empty(statusCode, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressLint({"NewApi", "ObsoleteSdkInt"})
|
||||
static int getCursorType(Cursor cursor, int i) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
return cursor.getType(i);
|
||||
}
|
||||
if (cursor instanceof AbstractWindowedCursor) {
|
||||
CursorWindow cursorWindow = ((AbstractWindowedCursor) cursor).getWindow();
|
||||
int pos = cursor.getPosition();
|
||||
int type = -1;
|
||||
if (cursorWindow.isNull(pos, i)) {
|
||||
type = FIELD_TYPE_NULL;
|
||||
} else if (cursorWindow.isLong(pos, i)) {
|
||||
type = FIELD_TYPE_INTEGER;
|
||||
} else if (cursorWindow.isFloat(pos, i)) {
|
||||
type = FIELD_TYPE_FLOAT;
|
||||
} else if (cursorWindow.isString(pos, i)) {
|
||||
type = FIELD_TYPE_STRING;
|
||||
} else if (cursorWindow.isBlob(pos, i)) {
|
||||
type = FIELD_TYPE_BLOB;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
throw new RuntimeException("Unsupported cursor on this platform!");
|
||||
return cursor.getType(i);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -194,20 +131,6 @@ public class DataHolder extends AutoSafeParcelable implements Closeable {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the String content in the given column at the provided position into a {@link CharArrayBuffer}.
|
||||
* This will throw an {@link IllegalArgumentException} if the column does not exist, the
|
||||
* position is invalid, or the data holder has been closed.
|
||||
*
|
||||
* @param column The column to retrieve.
|
||||
* @param row The row to retrieve the data from.
|
||||
* @param windowIndex Index of the cursor window to extract the data from.
|
||||
* @param dataOut The {@link CharArrayBuffer} to copy into.
|
||||
*/
|
||||
public void copyToBuffer(String column, int row, int windowIndex, CharArrayBuffer dataOut) {
|
||||
throw new RuntimeException("Not yet available");
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static CursorWindow[] createCursorWindows(Builder builder) {
|
||||
if (builder.columns.length == 0) return new CursorWindow[0];
|
||||
|
|
@ -300,34 +223,6 @@ public class DataHolder extends AutoSafeParcelable implements Closeable {
|
|||
return windows.toArray(new CursorWindow[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the boolean value for a given column at the provided position.
|
||||
* This will throw an {@link IllegalArgumentException} if the column does not exist, the
|
||||
* position is invalid, or the data holder has been closed.
|
||||
*
|
||||
* @param column The column to retrieve.
|
||||
* @param row The row to retrieve the data from.
|
||||
* @param windowIndex Index of the cursor window to extract the data from.
|
||||
* @return The boolean value in that column.
|
||||
*/
|
||||
public boolean getBoolean(String column, int row, int windowIndex) {
|
||||
return windows[windowIndex].getLong(row, columnIndices.get(column)) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the byte array value for a given column at the provided position.
|
||||
* This will throw an {@link IllegalArgumentException} if the column does not exist, the
|
||||
* position is invalid, or the data holder has been closed.
|
||||
*
|
||||
* @param column The column to retrieve.
|
||||
* @param row The row to retrieve the data from.
|
||||
* @param windowIndex Index of the cursor window to extract the data from.
|
||||
* @return The byte array value in that column.
|
||||
*/
|
||||
public byte[] getByteArray(String column, int row, int windowIndex) {
|
||||
return windows[windowIndex].getBlob(row, columnIndices.get(column));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of rows in the data holder.
|
||||
*
|
||||
|
|
@ -343,38 +238,6 @@ public class DataHolder extends AutoSafeParcelable implements Closeable {
|
|||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the integer value for a given column at the provided position.
|
||||
* This will throw an {@link IllegalArgumentException} if the column does not exist, the
|
||||
* position is invalid, or the data holder has been closed.
|
||||
*
|
||||
* @param column The column to retrieve.
|
||||
* @param row The row to retrieve the data from.
|
||||
* @param windowIndex Index of the cursor window to extract the data from.
|
||||
* @return The integer value in that column.
|
||||
*/
|
||||
public int getInteger(String column, int row, int windowIndex) {
|
||||
return windows[windowIndex].getInt(row, columnIndices.get(column));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the long value for a given column at the provided position.
|
||||
* This will throw an {@link IllegalArgumentException} if the column does not exist, the
|
||||
* position is invalid, or the data holder has been closed.
|
||||
*
|
||||
* @param column The column to retrieve.
|
||||
* @param row The row to retrieve the data from.
|
||||
* @param windowIndex Index of the cursor window to extract the data from.
|
||||
* @return The long value in that column.
|
||||
*/
|
||||
public long getLong(String column, int row, int windowIndex) {
|
||||
return windows[windowIndex].getLong(row, columnIndices.get(column));
|
||||
}
|
||||
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the string value for a given column at the provided position.
|
||||
* This will throw an {@link IllegalArgumentException} if the column does not exist, the
|
||||
|
|
@ -389,42 +252,6 @@ public class DataHolder extends AutoSafeParcelable implements Closeable {
|
|||
return windows[windowIndex].getString(row, columnIndices.get(column));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given column at the provided position contains null.
|
||||
* This will throw an {@link IllegalArgumentException} if the column does not exist, the
|
||||
* position is invalid, or the data holder has been closed.
|
||||
*
|
||||
* @param column The column to retrieve.
|
||||
* @param row The row to retrieve the data from.
|
||||
* @param windowIndex Index of the cursor window to extract the data from.
|
||||
* @return Whether the column value is null at this position.
|
||||
*/
|
||||
public boolean isNull(String column, int row, int windowIndex) {
|
||||
return windows[windowIndex].isNull(row, columnIndices.get(column));
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
synchronized (this) {
|
||||
return closed;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the column data at the provided position as a URI if possible, checking for null values.
|
||||
* This will throw an {@link IllegalArgumentException} if the column does not exist, the
|
||||
* position is invalid, or the data holder has been closed.
|
||||
*
|
||||
* @param column The column to retrieve.
|
||||
* @param row The row to retrieve the data from.
|
||||
* @param windowIndex Index of the cursor window to extract the data from.
|
||||
* @return The column data as a URI, or null if not present.
|
||||
*/
|
||||
public Uri parseUri(String column, int row, int windowIndex) {
|
||||
String string = getString(column, row, windowIndex);
|
||||
if (string != null) return Uri.parse(string);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DataHolder{" +
|
||||
|
|
@ -488,18 +315,6 @@ public class DataHolder extends AutoSafeParcelable implements Closeable {
|
|||
return rows.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the rows in this builder based on the standard data type comparisons for the value in the provided column.
|
||||
* Calling this multiple times with the same column will not change the sort order of the builder.
|
||||
* Note that any data which is added after this call will not be sorted.
|
||||
*
|
||||
* @param sortColumn The column to sort the rows in this builder by.
|
||||
* @return {@link DataHolder.Builder} to continue construction.
|
||||
*/
|
||||
public Builder sort(String sortColumn) {
|
||||
throw new RuntimeException("Not yet implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new row of data to the {@link DataHolder} this {@link DataHolder.Builder} will create. Note that the data must contain an entry for all columns
|
||||
* <p/>
|
||||
|
|
|
|||
|
|
@ -101,15 +101,7 @@ public class DeviceConfiguration {
|
|||
@SuppressWarnings({"deprecation", "InlinedApi"})
|
||||
private static List<String> getNativePlatforms() {
|
||||
List<String> nativePlatforms;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
return Arrays.asList(Build.SUPPORTED_ABIS);
|
||||
} else {
|
||||
nativePlatforms = new ArrayList<>();
|
||||
nativePlatforms.add(Build.CPU_ABI);
|
||||
if (Build.CPU_ABI2 != null && !Build.CPU_ABI2.equals("unknown"))
|
||||
nativePlatforms.add(Build.CPU_ABI2);
|
||||
return nativePlatforms;
|
||||
}
|
||||
return Arrays.asList(Build.SUPPORTED_ABIS);
|
||||
}
|
||||
|
||||
private static void addEglExtensions(Set<String> glExtensions) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.microg.gms.common;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
|
|
@ -15,7 +16,6 @@ import android.os.PowerManager;
|
|||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import org.microg.gms.base.core.R;
|
||||
|
|
@ -30,8 +30,7 @@ public class ForegroundServiceContext extends ContextWrapper {
|
|||
|
||||
@Override
|
||||
public ComponentName startService(Intent service) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
&& !isIgnoringBatteryOptimizations()) {
|
||||
if (!isIgnoringBatteryOptimizations()) {
|
||||
Log.d(TAG, "Starting in foreground mode.");
|
||||
service.putExtra(EXTRA_FOREGROUND, true);
|
||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
|
|
@ -43,7 +42,6 @@ public class ForegroundServiceContext extends ContextWrapper {
|
|||
return super.startService(service);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
private boolean isIgnoringBatteryOptimizations() {
|
||||
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||
return powerManager.isIgnoringBatteryOptimizations(getPackageName());
|
||||
|
|
@ -73,9 +71,7 @@ public class ForegroundServiceContext extends ContextWrapper {
|
|||
}
|
||||
|
||||
public static void completeForegroundService(Service service, Intent intent, String tag) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
&& intent != null
|
||||
&& intent.getBooleanExtra(EXTRA_FOREGROUND, false)) {
|
||||
if (intent != null && intent.getBooleanExtra(EXTRA_FOREGROUND, false)) {
|
||||
String serviceName = getServiceName(service);
|
||||
Log.d(tag, "Started " + serviceName + " in foreground mode.");
|
||||
try {
|
||||
|
|
@ -88,6 +84,7 @@ public class ForegroundServiceContext extends ContextWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("BatteryLife")
|
||||
private static Notification buildForegroundNotification(Context context, String serviceName) {
|
||||
Intent notificationIntent = new Intent();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
|
|
|
|||
|
|
@ -16,10 +16,6 @@
|
|||
|
||||
package org.microg.gms.common;
|
||||
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static org.microg.gms.common.Constants.GMS_PACKAGE_NAME;
|
||||
import static org.microg.gms.common.Constants.GMS_PACKAGE_SIGNATURE_SHA1;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Application;
|
||||
import android.app.PendingIntent;
|
||||
|
|
@ -40,11 +36,17 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static org.microg.gms.common.Constants.GMS_PACKAGE_NAME;
|
||||
import static org.microg.gms.common.Constants.GMS_PACKAGE_SIGNATURE_SHA1;
|
||||
import static org.microg.gms.common.Constants.GMS_SECONDARY_PACKAGE_SIGNATURE_SHA1;
|
||||
|
||||
public class PackageUtils {
|
||||
|
||||
private static final String GOOGLE_PLATFORM_KEY = GMS_PACKAGE_SIGNATURE_SHA1;
|
||||
private static final String GOOGLE_LEGACY_KEY = "58e1c4133f7441ec3d2c270270a14802da47ba0e"; // Seems to be no longer used.
|
||||
private static final String[] GOOGLE_PRIMARY_KEYS = {GOOGLE_PLATFORM_KEY, "24bb24c05e47e0aefa68a58a766179d9b613a600", "afb0fed5eeaebdd86f56a97742f4b6b33ef59875", "61226bdb57cc32c8a2a9ef71f7bc9548e95dcc0b", "3a82b5ee26bc46bf68113d920e610cd090198d4a"};
|
||||
private static final String GOOGLE_PLATFORM_KEY_2 = GMS_SECONDARY_PACKAGE_SIGNATURE_SHA1;
|
||||
private static final String GOOGLE_APP_KEY = "24bb24c05e47e0aefa68a58a766179d9b613a600";
|
||||
private static final String[] GOOGLE_PRIMARY_KEYS = {GOOGLE_PLATFORM_KEY, GOOGLE_PLATFORM_KEY_2, GOOGLE_APP_KEY};
|
||||
|
||||
private static final Map<String, String> KNOWN_GOOGLE_PACKAGES;
|
||||
|
||||
|
|
@ -278,11 +280,7 @@ public class PackageUtils {
|
|||
@SuppressWarnings("deprecation")
|
||||
public static String packageFromPendingIntent(PendingIntent pi) {
|
||||
if (pi == null) return null;
|
||||
if (SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
return pi.getTargetPackage();
|
||||
} else {
|
||||
return pi.getCreatorPackage();
|
||||
}
|
||||
return pi.getCreatorPackage();
|
||||
}
|
||||
|
||||
public static String getProcessName() {
|
||||
|
|
@ -290,7 +288,7 @@ public class PackageUtils {
|
|||
return Application.getProcessName();
|
||||
try {
|
||||
Class<?> activityThread = Class.forName("android.app.ActivityThread");
|
||||
String methodName = android.os.Build.VERSION.SDK_INT >= 18 ? "currentProcessName" : "currentPackageName";
|
||||
String methodName = "currentProcessName";
|
||||
Method getProcessName = activityThread.getDeclaredMethod(methodName);
|
||||
return (String) getProcessName.invoke(null);
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package org.microg.gms.common;
|
||||
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH;
|
||||
import static org.microg.gms.common.Constants.GMS_PACKAGE_NAME;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
|
|
@ -36,6 +34,7 @@ import java.util.Set;
|
|||
public class MultiConnectionKeeper {
|
||||
private static final String TAG = "GmsMultiConKeeper";
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static MultiConnectionKeeper INSTANCE;
|
||||
|
||||
private final Context context;
|
||||
|
|
@ -137,9 +136,7 @@ public class MultiConnectionKeeper {
|
|||
intent = gmsIntent;
|
||||
}
|
||||
int flags = Context.BIND_AUTO_CREATE;
|
||||
if (SDK_INT >= ICE_CREAM_SANDWICH) {
|
||||
flags |= Context.BIND_ADJUST_WITH_ACTIVITY;
|
||||
}
|
||||
flags |= Context.BIND_ADJUST_WITH_ACTIVITY;
|
||||
bound = context.bindService(intent, serviceConnection, flags);
|
||||
if (!bound) {
|
||||
context.unbindService(serviceConnection);
|
||||
|
|
@ -150,10 +147,6 @@ public class MultiConnectionKeeper {
|
|||
return bound;
|
||||
}
|
||||
|
||||
public IBinder getBinder() {
|
||||
return binder;
|
||||
}
|
||||
|
||||
public void unbind() {
|
||||
Log.d(TAG, "Connection(" + actionString + ") : unbind()");
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -39,10 +39,33 @@ public class ObjectWrapper<T> extends IObjectWrapper.Stub {
|
|||
}
|
||||
IBinder binder = obj.asBinder();
|
||||
Field[] fields = binder.getClass().getDeclaredFields();
|
||||
if (fields.length != 1) {
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
if (fields.length < 1) {
|
||||
throw new IllegalArgumentException("No fields were found");
|
||||
}
|
||||
Field field = fields[0];
|
||||
|
||||
// Ignore synthetic field(s) from JaCoCo or elsewhere
|
||||
// https://www.jacoco.org/jacoco/trunk/doc/faq.html
|
||||
|
||||
@Nullable
|
||||
Field field = null;
|
||||
|
||||
for (Field currentField : fields) {
|
||||
if (currentField.isSynthetic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (field == null) {
|
||||
field = currentField;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Too many non-synthetic fields were found");
|
||||
}
|
||||
}
|
||||
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException("No non-synthetic fields were found");
|
||||
}
|
||||
|
||||
if (!field.isAccessible()) {
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
|
|
@ -72,6 +95,6 @@ public class ObjectWrapper<T> extends IObjectWrapper.Stub {
|
|||
}
|
||||
|
||||
public static <T> ObjectWrapper<T> wrap(T t) {
|
||||
return new ObjectWrapper<>(t);
|
||||
return new ObjectWrapper<T>(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,8 @@ public class Constants {
|
|||
public static final String GMS_PACKAGE_NAME = "com.google.android.gms";
|
||||
public static final String GSF_PACKAGE_NAME = "com.mgoogle.android.gsf";
|
||||
public static final String GMS_PACKAGE_SIGNATURE_SHA1 = "38918a453d07199354f8b19af05ec6562ced5788";
|
||||
public static final String GMS_SECONDARY_PACKAGE_SIGNATURE_SHA1 = "bd32424203e0fb25f36b57e5aa356f9bdd1da998";
|
||||
|
||||
@Deprecated
|
||||
public static final int MAX_REFERENCE_VERSION = GMS_VERSION_CODE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ apply plugin: 'com.android.library'
|
|||
|
||||
android {
|
||||
compileSdkVersion androidCompileSdk
|
||||
buildToolsVersion '30.0.3'
|
||||
buildToolsVersion androidBuildVersionTools
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion androidMinSdk
|
||||
|
|
@ -37,7 +37,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'androidx.appcompat:appcompat:1.5.1'
|
||||
implementation 'androidx.preference:preference:1.2.0'
|
||||
implementation "androidx.appcompat:appcompat:$appcompatVersion"
|
||||
implementation "androidx.preference:preference:$preferenceVersion"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,10 +17,7 @@
|
|||
|
||||
package org.microg.tools.ui;
|
||||
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
|
|
@ -70,9 +67,7 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||
LayoutInflater.from(context).inflate(R.layout.switch_bar, this);
|
||||
|
||||
mTextView = (TextView) findViewById(R.id.switch_text);
|
||||
if (SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
|
||||
mTextView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
|
||||
}
|
||||
mTextView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
|
||||
mLabel = getResources().getString(R.string.abc_capital_off);
|
||||
mSummarySpan = new TextAppearanceSpan(context, androidx.appcompat.R.style.TextAppearance_AppCompat_Widget_Switch);
|
||||
updateText();
|
||||
|
|
@ -81,9 +76,7 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||
// Prevent onSaveInstanceState() to be called as we are managing the state of the Switch
|
||||
// on our own
|
||||
mSwitch.setSaveEnabled(false);
|
||||
if (SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
mSwitch.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
|
||||
}
|
||||
mSwitch.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
|
||||
|
||||
addOnSwitchChangeListener((switchView, isChecked) -> setTextViewLabel(isChecked));
|
||||
|
||||
|
|
@ -121,39 +114,12 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||
mSwitch.setChecked(checked);
|
||||
}
|
||||
|
||||
public void setCheckedInternal(boolean checked) {
|
||||
setTextViewLabel(checked);
|
||||
mSwitch.setCheckedInternal(checked);
|
||||
}
|
||||
|
||||
public boolean isChecked() {
|
||||
return mSwitch.isChecked();
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
mTextView.setEnabled(enabled);
|
||||
mSwitch.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public final ToggleSwitch getSwitch() {
|
||||
return mSwitch;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (!isShowing()) {
|
||||
setVisibility(View.VISIBLE);
|
||||
mSwitch.setOnCheckedChangeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
if (isShowing()) {
|
||||
setVisibility(View.GONE);
|
||||
mSwitch.setOnCheckedChangeListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isShowing() {
|
||||
return (getVisibility() == View.VISIBLE);
|
||||
}
|
||||
|
|
@ -183,13 +149,6 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||
mSwitchChangeListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeOnSwitchChangeListener(OnSwitchChangeListener listener) {
|
||||
if (!mSwitchChangeListeners.contains(listener)) {
|
||||
throw new IllegalStateException("Cannot remove OnSwitchChangeListener");
|
||||
}
|
||||
mSwitchChangeListeners.remove(listener);
|
||||
}
|
||||
|
||||
static class SavedState extends BaseSavedState {
|
||||
boolean checked;
|
||||
boolean visible;
|
||||
|
|
@ -214,6 +173,7 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||
out.writeValue(visible);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SwitchBar.SavedState{"
|
||||
|
|
|
|||
|
|
@ -54,10 +54,8 @@ public class AccountContentProvider extends ContentProvider {
|
|||
@Nullable
|
||||
@Override
|
||||
public Bundle call(String method, String arg, Bundle extras) {
|
||||
String suggestedPackageName = null;
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
|
||||
suggestedPackageName = getCallingPackage();
|
||||
}
|
||||
String suggestedPackageName;
|
||||
suggestedPackageName = getCallingPackage();
|
||||
String packageName = PackageUtils.getAndCheckCallingPackage(getContext(), suggestedPackageName);
|
||||
Log.d(TAG, "Call " + method + " from " + packageName + " with arg " + arg);
|
||||
if (!PackageUtils.callerHasExtendedAccess(getContext())) {
|
||||
|
|
@ -73,9 +71,7 @@ public class AccountContentProvider extends ContentProvider {
|
|||
Account[] accounts = null;
|
||||
if (arg != null && (arg.equals(DEFAULT_ACCOUNT_TYPE) || arg.startsWith(DEFAULT_ACCOUNT_TYPE + "."))) {
|
||||
AccountManager am = AccountManager.get(getContext());
|
||||
if (Build.VERSION.SDK_INT >= 18) {
|
||||
accounts = am.getAccountsByTypeForPackage(arg, packageName);
|
||||
}
|
||||
accounts = am.getAccountsByTypeForPackage(arg, packageName);
|
||||
if (accounts == null || accounts.length == 0) {
|
||||
accounts = am.getAccountsByType(arg);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,7 +80,8 @@ public class CheckinClient {
|
|||
DeviceIdentifier deviceIdent, PhoneInfo phoneInfo,
|
||||
LastCheckinInfo checkinInfo, Locale locale,
|
||||
List<Account> accounts, Boolean brandSpoof) {
|
||||
CheckinRequest.Builder builder = new CheckinRequest.Builder()
|
||||
CheckinRequest.Builder builder;
|
||||
builder = new CheckinRequest.Builder()
|
||||
.accountCookie(new ArrayList<>())
|
||||
.androidId(checkinInfo.getAndroidId())
|
||||
.checkin(new CheckinRequest.Checkin.Builder()
|
||||
|
|
@ -102,7 +103,7 @@ public class CheckinClient {
|
|||
.cellOperator(phoneInfo.cellOperator)
|
||||
.event(Collections.singletonList(new CheckinRequest.Checkin.Event.Builder()
|
||||
.tag(checkinInfo.getAndroidId() == 0 ? "event_log_start" : "system_update")
|
||||
.value(checkinInfo.getAndroidId() == 0 ? null : "1536,0,-1,NULL")
|
||||
.value_(checkinInfo.getAndroidId() == 0 ? null : "1536,0,-1,NULL")
|
||||
.timeMs(new Date().getTime())
|
||||
.build()))
|
||||
.lastCheckinMs(checkinInfo.getLastCheckin())
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class CheckinManager {
|
|||
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
for (CheckinResponse.GservicesSetting setting : response.setting) {
|
||||
GServices.setString(resolver, setting.name.utf8(), setting.value.utf8());
|
||||
GServices.setString(resolver, setting.name.utf8(), setting.value_.utf8());
|
||||
}
|
||||
|
||||
return info;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ import android.os.Bundle;
|
|||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.os.Messenger;
|
||||
import android.os.Parcelable;
|
||||
import android.os.PowerManager;
|
||||
import android.os.SystemClock;
|
||||
|
|
@ -178,7 +177,7 @@ public class McsService extends Service implements Handler.Callback {
|
|||
heartbeatIntent = PendingIntent.getService(this, 0, new Intent(ACTION_HEARTBEAT, null, this, McsService.class), 0);
|
||||
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
||||
powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission("android.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST") == PackageManager.PERMISSION_GRANTED) {
|
||||
if (checkSelfPermission("android.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST") == PackageManager.PERMISSION_GRANTED) {
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
Class<?> powerExemptionManagerClass = Class.forName("android.os.PowerExemptionManager");
|
||||
|
|
@ -267,11 +266,7 @@ public class McsService extends Service implements Handler.Callback {
|
|||
long delay = getCurrentDelay();
|
||||
logd(context, "Scheduling reconnect in " + delay / 1000 + " seconds...");
|
||||
PendingIntent pi = PendingIntent.getBroadcast(context, 1, new Intent(ACTION_RECONNECT, null, context, TriggerReceiver.class), 0);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
alarmManager.setExactAndAllowWhileIdle(ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + delay, pi);
|
||||
} else {
|
||||
alarmManager.set(ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + delay, pi);
|
||||
}
|
||||
alarmManager.setExactAndAllowWhileIdle(ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + delay, pi);
|
||||
}
|
||||
|
||||
public void scheduleHeartbeat(Context context) {
|
||||
|
|
@ -282,18 +277,8 @@ public class McsService extends Service implements Handler.Callback {
|
|||
closeAll();
|
||||
}
|
||||
logd(context, "Scheduling heartbeat in " + heartbeatMs / 1000 + " seconds...");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
// This is supposed to work even when running in idle and without battery optimization disabled
|
||||
alarmManager.setExactAndAllowWhileIdle(ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + heartbeatMs, heartbeatIntent);
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
// With KitKat, the alarms become inexact by default, but with the newly available setWindow we can get inexact alarms with guarantees.
|
||||
// Schedule the alarm to fire within the interval [heartbeatMs/3*4, heartbeatMs]
|
||||
alarmManager.setWindow(ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + heartbeatMs / 4 * 3, heartbeatMs / 4,
|
||||
heartbeatIntent);
|
||||
} else {
|
||||
alarmManager.set(ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + heartbeatMs, heartbeatIntent);
|
||||
}
|
||||
|
||||
// This is supposed to work even when running in idle and without battery optimization disabled
|
||||
alarmManager.setExactAndAllowWhileIdle(ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + heartbeatMs, heartbeatIntent);
|
||||
}
|
||||
|
||||
public synchronized static long getCurrentDelay() {
|
||||
|
|
@ -339,7 +324,6 @@ public class McsService extends Service implements Handler.Callback {
|
|||
String messageId = intent.getStringExtra(EXTRA_MESSAGE_ID);
|
||||
String collapseKey = intent.getStringExtra(EXTRA_COLLAPSE_KEY);
|
||||
|
||||
Messenger messenger = intent.getParcelableExtra(EXTRA_MESSENGER);
|
||||
intent.removeExtra(EXTRA_MESSENGER);
|
||||
|
||||
Parcelable app = intent.getParcelableExtra(EXTRA_APP);
|
||||
|
|
@ -357,16 +341,8 @@ public class McsService extends Service implements Handler.Callback {
|
|||
}
|
||||
intent.removeExtra(EXTRA_APP);
|
||||
|
||||
int ttl;
|
||||
try {
|
||||
if (intent.hasExtra(EXTRA_TTL)) {
|
||||
ttl = Integer.parseInt(intent.getStringExtra(EXTRA_TTL));
|
||||
if (ttl < 0 || ttl > maxTtl) {
|
||||
ttl = maxTtl;
|
||||
}
|
||||
} else {
|
||||
ttl = maxTtl;
|
||||
}
|
||||
intent.hasExtra(EXTRA_TTL);
|
||||
} catch (NumberFormatException e) {
|
||||
// TODO: error TtlUnsupported
|
||||
Log.w(TAG, e);
|
||||
|
|
@ -404,7 +380,7 @@ public class McsService extends Service implements Handler.Callback {
|
|||
if (!key.startsWith("google.")) {
|
||||
Object val = extras.get(key);
|
||||
if (val instanceof String) {
|
||||
appData.add(new AppData.Builder().key(key).value((String) val).build());
|
||||
appData.add(new AppData.Builder().key(key).value_((String) val).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -545,7 +521,7 @@ public class McsService extends Service implements Handler.Callback {
|
|||
.resource(Long.toString(info.getAndroidId()))
|
||||
.user(Long.toString(info.getAndroidId()))
|
||||
.use_rmq2(true)
|
||||
.setting(Collections.singletonList(new Setting.Builder().name("new_vc").value("1").build()))
|
||||
.setting(Collections.singletonList(new Setting.Builder().name("new_vc").value_("1").build()))
|
||||
.received_persistent_id(GcmPrefs.get(this).getLastPersistedIds())
|
||||
.build();
|
||||
}
|
||||
|
|
@ -569,7 +545,7 @@ public class McsService extends Service implements Handler.Callback {
|
|||
}
|
||||
if (msg.token != null) intent.putExtra(EXTRA_COLLAPSE_KEY, msg.token);
|
||||
for (AppData appData : msg.app_data) {
|
||||
intent.putExtra(appData.key, appData.value);
|
||||
intent.putExtra(appData.key, appData.value_);
|
||||
}
|
||||
|
||||
String receiverPermission = null;
|
||||
|
|
@ -622,7 +598,7 @@ public class McsService extends Service implements Handler.Callback {
|
|||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error adding app" + packageName + " to the temp allowlist.", e);
|
||||
}
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
} else {
|
||||
try {
|
||||
if (getUserIdMethod != null && addPowerSaveTempWhitelistAppMethod != null && deviceIdleController != null) {
|
||||
int userId = (int) getUserIdMethod.invoke(null, getPackageManager().getApplicationInfo(packageName, 0).uid);
|
||||
|
|
@ -644,7 +620,7 @@ public class McsService extends Service implements Handler.Callback {
|
|||
.sent(System.currentTimeMillis() / 1000)
|
||||
.ttl(0)
|
||||
.category(SELF_CATEGORY)
|
||||
.app_data(Collections.singletonList(new AppData.Builder().key(IDLE_NOTIFICATION).value("false").build()));
|
||||
.app_data(Collections.singletonList(new AppData.Builder().key(IDLE_NOTIFICATION).value_("false").build()));
|
||||
if (inputStream.newStreamIdAvailable()) {
|
||||
msgResponse.last_stream_id_received(inputStream.getStreamId());
|
||||
}
|
||||
|
|
@ -717,7 +693,7 @@ public class McsService extends Service implements Handler.Callback {
|
|||
IqStanza.Builder iq = new IqStanza.Builder()
|
||||
.type(IqStanza.IqType.SET)
|
||||
.id("")
|
||||
.extension(new Extension.Builder().id(13).data(ByteString.EMPTY).build()) // StreamAck
|
||||
.extension(new Extension.Builder().id(13).data_(ByteString.EMPTY).build()) // StreamAck
|
||||
.status(0L);
|
||||
if (inputStream.newStreamIdAvailable()) {
|
||||
iq.last_stream_id_received(inputStream.getStreamId());
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import android.content.ContentValues;
|
|||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
@ -56,11 +55,7 @@ public class GServicesProvider extends ContentProvider {
|
|||
}
|
||||
|
||||
private String getCallingPackageName() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
return getCallingPackage();
|
||||
} else {
|
||||
return "unknown";
|
||||
}
|
||||
return getCallingPackage();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -72,11 +72,11 @@ class PushNotificationPreferencesFragment : PreferenceFragmentCompat() {
|
|||
val appContext = requireContext().applicationContext
|
||||
lifecycleScope.launchWhenStarted {
|
||||
val statusInfo = getGcmServiceInfo(appContext)
|
||||
pushStatusCategory.isVisible = statusInfo.configuration.enabled
|
||||
pushStatusCategory.isVisible = statusInfo != null && statusInfo.configuration.enabled
|
||||
pushStatus.summary = if (statusInfo.connected) {
|
||||
getString(R.string.gcm_network_state_connected, DateUtils.getRelativeTimeSpanString(statusInfo.startTimestamp, System.currentTimeMillis(), 0))
|
||||
appContext.getString(R.string.gcm_network_state_connected, DateUtils.getRelativeTimeSpanString(statusInfo.startTimestamp, System.currentTimeMillis(), 0))
|
||||
} else {
|
||||
getString(R.string.gcm_network_state_disconnected)
|
||||
appContext.getString(R.string.gcm_network_state_disconnected)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {}
|
||||
|
|
|
|||
|
|
@ -42,13 +42,9 @@ class SettingsFragment : ResourceSettingsFragment() {
|
|||
findPreference<Preference>(PREF_ABOUT)?.summary = getString(R.string.about_version_str, AboutFragment.getSelfVersion(context))
|
||||
|
||||
findPreference<SwitchPreferenceCompat>(SettingsContract.CheckIn.HIDE_LAUNCHER_ICON)?.apply {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
requireActivity().hideIcon(newValue as Boolean)
|
||||
true
|
||||
}
|
||||
} else {
|
||||
preferenceScreen.removePreference(this)
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
requireActivity().hideIcon(newValue as Boolean)
|
||||
true
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,12 +11,10 @@ import android.content.ComponentName
|
|||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.navOptions
|
||||
import androidx.navigation.ui.R
|
||||
|
|
@ -41,7 +39,6 @@ fun NavController.navigate(context: Context, @IdRes resId: Int, args: Bundle? =
|
|||
} else null)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
fun Context.hideIcon(hide: Boolean) {
|
||||
packageManager.setComponentEnabledSetting(
|
||||
ComponentName.createRelative(this, "org.microg.gms.ui.SettingsActivityLauncher"),
|
||||
|
|
|
|||
|
|
@ -16,9 +16,6 @@
|
|||
|
||||
package com.google.android.gms.iid;
|
||||
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static android.os.Build.VERSION_CODES.LOLLIPOP;
|
||||
|
||||
import android.os.Binder;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
|
|
@ -29,23 +26,15 @@ import android.os.Parcelable;
|
|||
import android.os.RemoteException;
|
||||
|
||||
public class MessengerCompat implements Parcelable {
|
||||
private Messenger messenger;
|
||||
private final Messenger messenger;
|
||||
private IMessengerCompat messengerCompat;
|
||||
|
||||
public MessengerCompat(IBinder binder) {
|
||||
if (SDK_INT >= LOLLIPOP) {
|
||||
messenger = new Messenger(binder);
|
||||
} else {
|
||||
messengerCompat = IMessengerCompat.Stub.asInterface(binder);
|
||||
}
|
||||
messenger = new Messenger(binder);
|
||||
}
|
||||
|
||||
public MessengerCompat(Handler handler) {
|
||||
if (SDK_INT >= LOLLIPOP) {
|
||||
messenger = new Messenger(handler);
|
||||
} else {
|
||||
messengerCompat = new IMessengerCompatImpl(handler);
|
||||
}
|
||||
messenger = new Messenger(handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -59,7 +48,7 @@ public class MessengerCompat implements Parcelable {
|
|||
}
|
||||
|
||||
public IBinder getBinder() {
|
||||
return messenger != null ? messenger.getBinder() : messengerCompat.asBinder();
|
||||
return messenger.getBinder();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -68,8 +57,7 @@ public class MessengerCompat implements Parcelable {
|
|||
}
|
||||
|
||||
public void send(Message message) throws RemoteException {
|
||||
if (messenger != null) messenger.send(message);
|
||||
else messengerCompat.send(message);
|
||||
messenger.send(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in a new issue