diff --git a/play-services-base/src/main/java/org/microg/gms/common/GmsConnector.java b/play-services-base/src/main/java/org/microg/gms/common/GmsConnector.java index 41c39d40..9a56566c 100644 --- a/play-services-base/src/main/java/org/microg/gms/common/GmsConnector.java +++ b/play-services-base/src/main/java/org/microg/gms/common/GmsConnector.java @@ -78,12 +78,9 @@ public class GmsConnector { final AbstractPendingResult result = (AbstractPendingResult) msg.obj; try { C connection = (C) apiClient.getApiConnection(api); - callback.onClientAvailable(connection, new GmsConnector.Callback.ResultProvider() { - @Override - public void onResultAvailable(R realResult) { - result.deliverResult(realResult); - apiClient.decrementUsageCounter(); - } + callback.onClientAvailable(connection, realResult -> { + result.deliverResult(realResult); + apiClient.decrementUsageCounter(); }); } catch (RemoteException ignored) { diff --git a/play-services-base/src/main/java/org/microg/gms/common/api/GoogleApiClientImpl.java b/play-services-base/src/main/java/org/microg/gms/common/api/GoogleApiClientImpl.java index f2b3ed0a..e59f68f6 100644 --- a/play-services-base/src/main/java/org/microg/gms/common/api/GoogleApiClientImpl.java +++ b/play-services-base/src/main/java/org/microg/gms/common/api/GoogleApiClientImpl.java @@ -19,12 +19,10 @@ package org.microg.gms.common.api; import android.content.Context; import android.os.Bundle; import android.os.Looper; -import android.os.Message; +import android.util.Log; import androidx.fragment.app.FragmentActivity; -import android.util.Log; - import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.Api; import com.google.android.gms.common.api.GoogleApiClient; @@ -65,16 +63,12 @@ public class GoogleApiClientImpl implements GoogleApiClient { } } }; - private final OnConnectionFailedListener baseConnectionFailedListener = new - OnConnectionFailedListener() { - @Override - public void onConnectionFailed(ConnectionResult result) { - Log.d(TAG, "OnConnectionFailedListener : onConnectionFailed()"); - for (OnConnectionFailedListener listener : connectionFailedListeners) { - listener.onConnectionFailed(result); - } - } - }; + private final OnConnectionFailedListener baseConnectionFailedListener = result -> { + Log.d(TAG, "OnConnectionFailedListener : onConnectionFailed()"); + for (OnConnectionFailedListener listener : connectionFailedListeners) { + listener.onConnectionFailed(result); + } + }; private int usageCounter = 0; private boolean shouldDisconnect = false; diff --git a/play-services-core/microg-ui-tools/src/main/java/org/microg/tools/ui/AbstractDashboardActivity.java b/play-services-core/microg-ui-tools/src/main/java/org/microg/tools/ui/AbstractDashboardActivity.java index f926b4c1..30bf98c8 100644 --- a/play-services-core/microg-ui-tools/src/main/java/org/microg/tools/ui/AbstractDashboardActivity.java +++ b/play-services-core/microg-ui-tools/src/main/java/org/microg/tools/ui/AbstractDashboardActivity.java @@ -47,19 +47,13 @@ public abstract class AbstractDashboardActivity extends AppCompatActivity { private void evaluateConditionAsync(final Condition condition) { if (condition.willBeEvaluating()) { - new Thread(new Runnable() { - @Override - public void run() { - if (condition.isActive(AbstractDashboardActivity.this)) { - runOnUiThread(new Runnable() { - @Override - public void run() { - if (conditions.contains(condition) && condition.isEvaluated()) { - addConditionToView(condition); - } - } - }); - } + new Thread(() -> { + if (condition.isActive(AbstractDashboardActivity.this)) { + runOnUiThread(() -> { + if (conditions.contains(condition) && condition.isEvaluated()) { + addConditionToView(condition); + } + }); } }).start(); } diff --git a/play-services-core/microg-ui-tools/src/main/java/org/microg/tools/ui/Condition.java b/play-services-core/microg-ui-tools/src/main/java/org/microg/tools/ui/Condition.java index 7ea35cd8..5adeeb88 100644 --- a/play-services-core/microg-ui-tools/src/main/java/org/microg/tools/ui/Condition.java +++ b/play-services-core/microg-ui-tools/src/main/java/org/microg/tools/ui/Condition.java @@ -108,16 +108,13 @@ public class Condition { } final View detailGroup = view.findViewById(R.id.detail_group); final ImageView expandIndicator = (ImageView) view.findViewById(R.id.expand_indicator); - View.OnClickListener expandListener = new View.OnClickListener() { - @Override - public void onClick(View v) { - if (detailGroup.getVisibility() == View.VISIBLE) { - expandIndicator.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.ic_expand_more, context.getTheme())); - detailGroup.setVisibility(View.GONE); - } else { - expandIndicator.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.ic_expand_less, context.getTheme())); - detailGroup.setVisibility(View.VISIBLE); - } + View.OnClickListener expandListener = v -> { + if (detailGroup.getVisibility() == View.VISIBLE) { + expandIndicator.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.ic_expand_more, context.getTheme())); + detailGroup.setVisibility(View.GONE); + } else { + expandIndicator.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.ic_expand_less, context.getTheme())); + detailGroup.setVisibility(View.VISIBLE); } }; view.findViewById(R.id.collapsed_group).setOnClickListener(expandListener); diff --git a/play-services-core/microg-ui-tools/src/main/java/org/microg/tools/ui/SwitchBar.java b/play-services-core/microg-ui-tools/src/main/java/org/microg/tools/ui/SwitchBar.java index 6b405646..61f28ae5 100644 --- a/play-services-core/microg-ui-tools/src/main/java/org/microg/tools/ui/SwitchBar.java +++ b/play-services-core/microg-ui-tools/src/main/java/org/microg/tools/ui/SwitchBar.java @@ -85,12 +85,7 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC mSwitch.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); } - addOnSwitchChangeListener(new OnSwitchChangeListener() { - @Override - public void onSwitchChanged(SwitchCompat switchView, boolean isChecked) { - setTextViewLabel(isChecked); - } - }); + addOnSwitchChangeListener((switchView, isChecked) -> setTextViewLabel(isChecked)); setOnClickListener(this); diff --git a/play-services-core/src/main/java/org/microg/gms/auth/AskPermissionActivity.java b/play-services-core/src/main/java/org/microg/gms/auth/AskPermissionActivity.java index ebc24dfa..e3317d71 100644 --- a/play-services-core/src/main/java/org/microg/gms/auth/AskPermissionActivity.java +++ b/play-services-core/src/main/java/org/microg/gms/auth/AskPermissionActivity.java @@ -25,7 +25,6 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; -import android.os.Build; import android.os.Bundle; import android.text.Html; import android.util.Log; @@ -39,7 +38,6 @@ import android.widget.ListView; import android.widget.TextView; import com.mgoogle.android.gms.R; -import com.squareup.wire.Wire; import org.microg.gms.common.PackageUtils; import org.microg.gms.people.PeopleManager; @@ -119,18 +117,10 @@ public class AskPermissionActivity extends AccountAuthenticatorActivity { if (profileIcon != null) { ((ImageView) findViewById(R.id.account_photo)).setImageBitmap(profileIcon); } else { - new Thread(new Runnable() { - @Override - public void run() { - final Bitmap profileIcon = PeopleManager.getOwnerAvatarBitmap(AskPermissionActivity.this, account.name, true); - runOnUiThread(new Runnable() { - @Override - public void run() { - ((ImageView) findViewById(R.id.account_photo)).setImageBitmap(profileIcon); - } - }); + new Thread(() -> { + final Bitmap profileIcon1 = PeopleManager.getOwnerAvatarBitmap(AskPermissionActivity.this, account.name, true); + runOnUiThread(() -> ((ImageView) findViewById(R.id.account_photo)).setImageBitmap(profileIcon1)); - } }).start(); } @@ -140,18 +130,8 @@ public class AskPermissionActivity extends AccountAuthenticatorActivity { } else { ((TextView) findViewById(R.id.title)).setText(getString(R.string.ask_service_permission_title, appLabel)); } - findViewById(android.R.id.button1).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onAllow(); - } - }); - findViewById(android.R.id.button2).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onDeny(); - } - }); + findViewById(android.R.id.button1).setOnClickListener(v -> onAllow()); + findViewById(android.R.id.button2).setOnClickListener(v -> onDeny()); ((ListView) findViewById(R.id.permissions)).setAdapter(new PermissionAdapter()); } @@ -161,24 +141,21 @@ public class AskPermissionActivity extends AccountAuthenticatorActivity { findViewById(android.R.id.button2).setEnabled(false); findViewById(R.id.progress_bar).setVisibility(VISIBLE); findViewById(R.id.no_progress_bar).setVisibility(GONE); - new Thread(new Runnable() { - @Override - public void run() { - try { - AuthResponse response = authManager.requestAuth(fromAccountManager); - Bundle result = new Bundle(); - result.putString(KEY_AUTHTOKEN, response.auth); - result.putString(KEY_ACCOUNT_NAME, account.name); - result.putString(KEY_ACCOUNT_TYPE, account.type); - result.putString(KEY_ANDROID_PACKAGE_NAME, packageName); - result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true); - setAccountAuthenticatorResult(result); - } catch (IOException e) { - Log.w(TAG, e); - } - finish(); - + new Thread(() -> { + try { + AuthResponse response = authManager.requestAuth(fromAccountManager); + Bundle result = new Bundle(); + result.putString(KEY_AUTHTOKEN, response.auth); + result.putString(KEY_ACCOUNT_NAME, account.name); + result.putString(KEY_ACCOUNT_TYPE, account.type); + result.putString(KEY_ANDROID_PACKAGE_NAME, packageName); + result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true); + setAccountAuthenticatorResult(result); + } catch (IOException e) { + Log.w(TAG, e); } + finish(); + }).start(); } diff --git a/play-services-core/src/main/java/org/microg/gms/auth/login/AssistantActivity.java b/play-services-core/src/main/java/org/microg/gms/auth/login/AssistantActivity.java index 21164946..a967e501 100644 --- a/play-services-core/src/main/java/org/microg/gms/auth/login/AssistantActivity.java +++ b/play-services-core/src/main/java/org/microg/gms/auth/login/AssistantActivity.java @@ -23,7 +23,6 @@ import android.os.Bundle; import android.util.DisplayMetrics; import android.view.View; import android.widget.Button; -import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.StringRes; @@ -39,18 +38,8 @@ public abstract class AssistantActivity extends Activity { super.onCreate(savedInstanceState); setContentView(R.layout.login_assistant); formatTitle(); - findViewById(R.id.next_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onNextButtonClicked(); - } - }); - findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onBackButtonClicked(); - } - }); + findViewById(R.id.next_button).setOnClickListener(v -> onNextButtonClicked()); + findViewById(R.id.back_button).setOnClickListener(v -> onBackButtonClicked()); } @SuppressLint("WrongViewCast") diff --git a/play-services-core/src/main/java/org/microg/gms/cast/CastMediaRouteProvider.java b/play-services-core/src/main/java/org/microg/gms/cast/CastMediaRouteProvider.java index 379bbf41..0a2d8b0e 100644 --- a/play-services-core/src/main/java/org/microg/gms/cast/CastMediaRouteProvider.java +++ b/play-services-core/src/main/java/org/microg/gms/cast/CastMediaRouteProvider.java @@ -307,12 +307,7 @@ public class CastMediaRouteProvider extends MediaRouteProvider { private void publishRoutesInMainThread() { Handler mainHandler = new Handler(this.getContext().getMainLooper()); - mainHandler.post(new Runnable() { - @Override - public void run() { - publishRoutes(); - } - }); + mainHandler.post(this::publishRoutes); } private void publishRoutes() { diff --git a/play-services-core/src/main/java/org/microg/gms/common/HttpFormClient.java b/play-services-core/src/main/java/org/microg/gms/common/HttpFormClient.java index 5838258f..2ad23c70 100644 --- a/play-services-core/src/main/java/org/microg/gms/common/HttpFormClient.java +++ b/play-services-core/src/main/java/org/microg/gms/common/HttpFormClient.java @@ -191,14 +191,11 @@ public class HttpFormClient { public static void requestAsync(final String url, final Request request, final Class tClass, final Callback callback) { - new Thread(new Runnable() { - @Override - public void run() { - try { - callback.onResponse(request(url, request, tClass)); - } catch (Exception e) { - callback.onException(e); - } + new Thread(() -> { + try { + callback.onResponse(request(url, request, tClass)); + } catch (Exception e) { + callback.onException(e); } }).start(); } diff --git a/play-services-core/src/main/java/org/microg/gms/common/RemoteListenerProxy.java b/play-services-core/src/main/java/org/microg/gms/common/RemoteListenerProxy.java index b562ee84..e14aea00 100644 --- a/play-services-core/src/main/java/org/microg/gms/common/RemoteListenerProxy.java +++ b/play-services-core/src/main/java/org/microg/gms/common/RemoteListenerProxy.java @@ -117,15 +117,12 @@ public class RemoteListenerProxy implements ServiceConnect @Override public Object invoke(Object proxy, final Method method, final Object[] args) throws Throwable { if (method.getDeclaringClass().equals(tClass)) { - runOncePossible(new Runnable() { - @Override - public void run() { - try { - Object asInterface = Class.forName(tClass.getName() + "$Stub").getMethod("asInterface", IBinder.class).invoke(null, remote); - method.invoke(asInterface, args); - } catch (Exception e) { - Log.w(TAG, e); - } + runOncePossible(() -> { + try { + Object asInterface = Class.forName(tClass.getName() + "$Stub").getMethod("asInterface", IBinder.class).invoke(null, remote); + method.invoke(asInterface, args); + } catch (Exception e) { + Log.w(TAG, e); } }); connect(); diff --git a/play-services-core/src/main/java/org/microg/gms/gcm/UnregisterReceiver.java b/play-services-core/src/main/java/org/microg/gms/gcm/UnregisterReceiver.java index bba2e414..ebc3cf72 100644 --- a/play-services-core/src/main/java/org/microg/gms/gcm/UnregisterReceiver.java +++ b/play-services-core/src/main/java/org/microg/gms/gcm/UnregisterReceiver.java @@ -28,19 +28,16 @@ public class UnregisterReceiver extends BroadcastReceiver { Log.d(TAG, "Package removed or data cleared: " + packageName); final GcmDatabase.App app = database.getApp(packageName); if (app != null) { - new Thread(new Runnable() { - @Override - public void run() { - List registrations = database.getRegistrationsByApp(packageName); - boolean deletedAll = true; - for (GcmDatabase.Registration registration : registrations) { - deletedAll &= PushRegisterManager.unregister(context, registration.packageName, registration.signature, null, null).deleted != null; - } - if (deletedAll) { - database.removeApp(packageName); - } - database.close(); + new Thread(() -> { + List registrations = database.getRegistrationsByApp(packageName); + boolean deletedAll = true; + for (GcmDatabase.Registration registration : registrations) { + deletedAll &= PushRegisterManager.unregister(context, registration.packageName, registration.signature, null, null).deleted != null; } + if (deletedAll) { + database.removeApp(packageName); + } + database.close(); }).start(); } else { database.close(); diff --git a/play-services-core/src/main/java/org/microg/gms/people/PeopleServiceImpl.java b/play-services-core/src/main/java/org/microg/gms/people/PeopleServiceImpl.java index d68e23d2..dbccb1c8 100644 --- a/play-services-core/src/main/java/org/microg/gms/people/PeopleServiceImpl.java +++ b/play-services-core/src/main/java/org/microg/gms/people/PeopleServiceImpl.java @@ -16,11 +16,9 @@ package org.microg.gms.people; -import android.Manifest; import android.accounts.Account; import android.accounts.AccountManager; import android.content.Context; -import android.content.pm.PackageManager; import android.database.Cursor; import android.os.Bundle; import android.os.Parcel; @@ -118,23 +116,20 @@ public class PeopleServiceImpl extends IPeopleService.Stub { public ICancelToken loadOwnerAvatar(final IPeopleCallbacks callbacks, final String account, String pageId, int size, int flags) { Log.d(TAG, "loadOwnerAvatar: " + account + ", " + pageId + ", " + size + ", " + flags); PackageUtils.assertExtendedAccess(context); - final Thread thread = new Thread(new Runnable() { - @Override - public void run() { - Bundle extras = new Bundle(); - extras.putBoolean("rewindable", false); - extras.putInt("width", 0); - extras.putInt("height", 0); - File avaterFile = PeopleManager.getOwnerAvaterFile(context, account, true); - try { - ParcelFileDescriptor fileDescriptor = null; - if (avaterFile != null) { - fileDescriptor = ParcelFileDescriptor.open(avaterFile, ParcelFileDescriptor.MODE_READ_ONLY); - } - callbacks.onParcelFileDescriptor(0, extras, fileDescriptor, extras); - } catch (Exception e) { - Log.w(TAG, e); + final Thread thread = new Thread(() -> { + Bundle extras = new Bundle(); + extras.putBoolean("rewindable", false); + extras.putInt("width", 0); + extras.putInt("height", 0); + File avaterFile = PeopleManager.getOwnerAvaterFile(context, account, true); + try { + ParcelFileDescriptor fileDescriptor = null; + if (avaterFile != null) { + fileDescriptor = ParcelFileDescriptor.open(avaterFile, ParcelFileDescriptor.MODE_READ_ONLY); } + callbacks.onParcelFileDescriptor(0, extras, fileDescriptor, extras); + } catch (Exception e) { + Log.w(TAG, e); } }); thread.start(); diff --git a/play-services-core/src/main/java/org/microg/gms/ui/AskPushPermission.java b/play-services-core/src/main/java/org/microg/gms/ui/AskPushPermission.java index 8e5014bc..bd1d4f37 100755 --- a/play-services-core/src/main/java/org/microg/gms/ui/AskPushPermission.java +++ b/play-services-core/src/main/java/org/microg/gms/ui/AskPushPermission.java @@ -5,7 +5,6 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; import android.text.Html; -import android.view.View; import android.widget.TextView; import androidx.fragment.app.FragmentActivity; @@ -58,30 +57,19 @@ public class AskPushPermission extends FragmentActivity { CharSequence label = pm.getApplicationLabel(info); ((TextView) findViewById(R.id.permission_message)).setText(Html.fromHtml("Allow " + label + " to register for push notifications?")); - findViewById(R.id.permission_allow_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (answered) return; - database.noteAppKnown(packageName, true); - answered = true; - new Thread(new Runnable() { - @Override - public void run() { - PushRegisterService.registerAndReply(AskPushPermission.this, database, intent, packageName, requestId); - } - }).start(); - finish(); - } + findViewById(R.id.permission_allow_button).setOnClickListener(v -> { + if (answered) return; + database.noteAppKnown(packageName, true); + answered = true; + new Thread(() -> PushRegisterService.registerAndReply(AskPushPermission.this, database, intent, packageName, requestId)).start(); + finish(); }); - findViewById(R.id.permission_deny_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (answered) return; - database.noteAppKnown(packageName, false); - answered = true; - PushRegisterService.replyNotAvailable(AskPushPermission.this, intent, packageName, requestId); - finish(); - } + findViewById(R.id.permission_deny_button).setOnClickListener(v -> { + if (answered) return; + database.noteAppKnown(packageName, false); + answered = true; + PushRegisterService.replyNotAvailable(AskPushPermission.this, intent, packageName, requestId); + finish(); }); } catch (PackageManager.NameNotFoundException e) { finish(); diff --git a/play-services-core/src/main/java/org/microg/gms/ui/Conditions.java b/play-services-core/src/main/java/org/microg/gms/ui/Conditions.java index a1d54823..8f852e0c 100755 --- a/play-services-core/src/main/java/org/microg/gms/ui/Conditions.java +++ b/play-services-core/src/main/java/org/microg/gms/ui/Conditions.java @@ -55,14 +55,11 @@ public class Conditions { return !pm.isIgnoringBatteryOptimizations(context.getPackageName()); } }) - .firstAction(R.string.cond_gcm_bat_action, new View.OnClickListener() { - @Override - public void onClick(View v) { - if (SDK_INT < 23) return; - Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); - intent.setData(Uri.parse("package:" + v.getContext().getPackageName())); - v.getContext().startActivity(intent); - } + .firstAction(R.string.cond_gcm_bat_action, v -> { + if (SDK_INT < 23) return; + Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); + intent.setData(Uri.parse("package:" + v.getContext().getPackageName())); + v.getContext().startActivity(intent); }).build(); }