Move UI into separate process

This commit is contained in:
Marvin W 2020-08-25 13:11:50 +02:00
parent 60cc63ed60
commit c88832213c
No known key found for this signature in database
GPG Key ID: 072E9235DB996F2A
4 changed files with 107 additions and 14 deletions

View File

@ -17,6 +17,7 @@
package org.microg.gms.common;
import android.app.ActivityManager;
import android.app.Application;
import android.app.PendingIntent;
import android.content.Context;
import android.content.pm.PackageInfo;
@ -26,6 +27,7 @@ import android.os.Binder;
import androidx.annotation.Nullable;
import java.lang.reflect.Method;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
@ -230,6 +232,19 @@ public class PackageUtils {
}
}
public static String getProcessName() {
if (android.os.Build.VERSION.SDK_INT >= 28)
return Application.getProcessName();
try {
Class<?> activityThread = Class.forName("android.app.ActivityThread");
String methodName = android.os.Build.VERSION.SDK_INT >= 18 ? "currentProcessName" : "currentPackageName";
Method getProcessName = activityThread.getDeclaredMethod(methodName);
return (String) getProcessName.invoke(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static String sha1sum(byte[] bytes) {
MessageDigest md;
try {

View File

@ -129,11 +129,11 @@
<!-- Location -->
<activity android:name="org.microg.nlp.ui.BackendSettingsActivity" />
<activity android:name="org.microg.nlp.ui.BackendSettingsActivity" android:process=":ui" />
<activity
android:name="org.microg.gms.ui.PlacePickerActivity"
android:exported="true"
android:exported="true" android:process=":ui"
android:label="@string/pick_place_title"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
<intent-filter>
@ -238,6 +238,8 @@
</intent-filter>
</receiver>
<receiver android:name="org.microg.gms.gcm.StatusInfoProvider" />
<receiver android:name="org.microg.gms.gcm.TriggerReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
@ -346,7 +348,8 @@
<activity
android:name="org.microg.tools.AccountPickerActivity"
android:excludeFromRecents="true"
android:exported="true">
android:exported="true"
android:process=":ui">
<intent-filter>
<action android:name="com.google.android.gms.common.account.CHOOSE_ACCOUNT" />
@ -358,6 +361,7 @@
android:name="org.microg.gms.auth.login.LoginActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:process=":ui"
android:theme="@style/Theme.LoginBlue">
<intent-filter>
<action android:name="com.google.android.gms.auth.login.LOGIN" />
@ -370,6 +374,7 @@
android:name="org.microg.gms.auth.AskPermissionActivity"
android:excludeFromRecents="true"
android:exported="true"
android:process=":ui"
android:theme="@style/Theme.AppCompat.DayNight.Dialog" />
<service
@ -378,7 +383,8 @@
<activity
android:name=".auth.TokenActivity"
android:exported="true" />
android:exported="true"
android:process=":ui" />
<provider
android:name="org.microg.gms.auth.AccountContentProvider"
@ -396,6 +402,7 @@
<activity
android:name="org.microg.gms.games.UpgradeActivity"
android:process=":ui"
android:theme="@style/Theme.AppCompat.DayNight.Dialog">
<intent-filter>
<action android:name="com.google.android.gms.games.PLAY_GAMES_UPGRADE" />
@ -422,6 +429,7 @@
<activity
android:name="org.microg.gms.ui.ExposureNotificationsConfirmActivity"
android:exported="false"
android:process=":ui"
android:theme="@style/Theme.AppCompat.DayNight.Dialog.Alert.NoActionBar">
<intent-filter>
<action android:name="org.microg.gms.nearby.exposurenotification.CONFIRM" />
@ -433,6 +441,7 @@
android:name="org.microg.gms.ui.SettingsActivity"
android:icon="@mipmap/ic_microg_settings"
android:label="@string/gms_settings_name"
android:process=":ui"
android:roundIcon="@mipmap/ic_microg_settings">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -441,6 +450,7 @@
<intent-filter>
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
<action android:name="com.google.android.gms.settings.EXPOSURE_NOTIFICATION_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
@ -449,6 +459,7 @@
android:name="org.microg.gms.ui.SettingsDashboardActivity"
android:icon="@mipmap/ic_microg_settings"
android:label="Legacy microG Settings"
android:process=":ui"
android:roundIcon="@mipmap/ic_microg_settings" />
<!-- microG Settings embedded in System Settings on SDK 23 and newer -->
@ -456,6 +467,7 @@
android:name="org.microg.gms.ui.SettingsActivityLink"
android:icon="@drawable/microg_light_color_24"
android:label="@string/gms_settings_name"
android:process=":ui"
android:targetActivity="org.microg.gms.ui.SettingsActivity">
<intent-filter>
<action android:name="com.android.settings.action.EXTRA_SETTINGS" />
@ -475,25 +487,32 @@
<activity
android:name="org.microg.gms.ui.AskPushPermission"
android:excludeFromRecents="true"
android:process=":ui"
android:theme="@style/Theme.AppCompat.DayNight.Dialog.Alert" />
<activity
android:name="org.microg.gms.ui.AboutFragment$AsActivity"
android:label="@string/pref_about_title" />
android:label="@string/pref_about_title"
android:process=":ui" />
<activity
android:name="org.microg.gms.ui.GoogleMoreFragment$AsActivity"
android:label="@string/gms_settings_name" />
android:label="@string/gms_settings_name"
android:process=":ui" />
<activity
android:name="org.microg.gms.ui.SafetyNetAdvancedFragment$AsActivity"
android:label="@string/service_name_snet" />
android:label="@string/service_name_snet"
android:process=":ui" />
<activity
android:name="org.microg.gms.ui.SelfCheckFragment$AsActivity"
android:label="@string/self_check_title" />
android:label="@string/self_check_title"
android:process=":ui" />
<activity android:name="org.microg.gms.ui.AccountSettingsActivity">
<activity
android:name="org.microg.gms.ui.AccountSettingsActivity"
android:process=":ui">
<intent-filter>
<action android:name="com.google.android.gms.accountsettings.ACCOUNT_PREFERENCES_SETTINGS" />
<action android:name="com.google.android.gms.accountsettings.PRIVACY_SETTINGS" />
@ -503,7 +522,9 @@
</intent-filter>
</activity>
<activity android:name="org.microg.gms.ui.LocationSettingsActivity">
<activity
android:name="org.microg.gms.ui.LocationSettingsActivity"
android:process=":ui">
<intent-filter>
<action android:name="com.google.android.gms.location.settings.LOCATION_HISTORY" />
<action android:name="com.google.android.location.settings.LOCATION_REPORTING_SETTINGS" />

View File

@ -0,0 +1,53 @@
/*
* SPDX-FileCopyrightText: 2020, microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/
package org.microg.gms.gcm
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.util.Log
import java.io.Serializable
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
private const val ACTION_STATUS_INFO_REQUEST = "org.microg.gms.STATUS_INFO_REQUEST"
private const val ACTION_STATUS_INFO_RESPONSE = "org.microg.gms.STATUS_INFO_RESPONSE"
private const val EXTRA_STATUS_INFO = "org.microg.gms.STATUS_INFO"
private const val TAG = "GmsGcmStatusInfo"
data class StatusInfo(val connected: Boolean, val startTimestamp: Long) : Serializable
class StatusInfoProvider : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
try {
context.sendOrderedBroadcast(Intent(ACTION_STATUS_INFO_RESPONSE).apply {
setPackage(context.packageName)
putExtra(EXTRA_STATUS_INFO, StatusInfo(McsService.isConnected(), McsService.getStartTimestamp()))
}, null)
} catch (e: Exception) {
Log.w(TAG, e)
}
}
}
suspend fun getStatusInfo(context: Context): StatusInfo? = suspendCoroutine {
context.registerReceiver(object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent?) {
try {
it.resume(intent?.getSerializableExtra(EXTRA_STATUS_INFO) as? StatusInfo)
} catch (e: Exception) {
Log.w(TAG, e)
}
context.unregisterReceiver(this)
}
}, IntentFilter(ACTION_STATUS_INFO_RESPONSE))
try {
context.sendOrderedBroadcast(Intent(context, StatusInfoProvider::class.java), null)
} catch (e: Exception) {
it.resume(null)
}
}

View File

@ -20,6 +20,7 @@ import kotlinx.coroutines.withContext
import org.microg.gms.gcm.GcmDatabase
import org.microg.gms.gcm.GcmPrefs
import org.microg.gms.gcm.McsService
import org.microg.gms.gcm.getStatusInfo
class PushNotificationPreferencesFragment : PreferenceFragmentCompat() {
private lateinit var pushStatusCategory: PreferenceCategory
@ -67,10 +68,13 @@ class PushNotificationPreferencesFragment : PreferenceFragmentCompat() {
private fun updateStatus() {
handler.postDelayed(updateRunnable, UPDATE_INTERVAL)
pushStatusCategory.isVisible = GcmPrefs.get(context).isEnabled
pushStatus.summary = if (McsService.isConnected()) {
getString(R.string.gcm_network_state_connected, DateUtils.getRelativeTimeSpanString(McsService.getStartTimestamp(), System.currentTimeMillis(), 0))
} else {
getString(R.string.gcm_network_state_disconnected)
lifecycleScope.launchWhenStarted {
val statusInfo = getStatusInfo(requireContext())
pushStatus.summary = if (statusInfo != null && statusInfo.connected) {
getString(R.string.gcm_network_state_connected, DateUtils.getRelativeTimeSpanString(statusInfo.startTimestamp, System.currentTimeMillis(), 0))
} else {
getString(R.string.gcm_network_state_disconnected)
}
}
}