Removing boot receiver.

> Registering the receiver at runtime, only when it is required
> Using system property sys.boot_completed to check if boot completion
> This prevents unnecessary process startup during system bootup

Change-Id: I68f99ecf2e1ffd2ca7b6d15a99a282451bf67aec
This commit is contained in:
Sunny Goyal
2015-07-16 15:07:47 -07:00
parent 8239daded4
commit 25aba0aea5
5 changed files with 19 additions and 26 deletions

View File

@@ -51,11 +51,9 @@
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.BIND_APPWIDGET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BROADCAST_STICKY"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.android.launcher.permission.WRITE_SETTINGS" />
@@ -204,12 +202,6 @@
</intent-filter>
</receiver>
<receiver android:name="com.android.launcher3.StartupReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<!-- The settings provider contains Home's data, like the workspace favorites -->
<provider
android:name="com.android.launcher3.LauncherProvider"

View File

@@ -1744,8 +1744,7 @@ public class LauncherModel extends BroadcastReceiver
final PackageManager manager = context.getPackageManager();
final boolean isSafeMode = manager.isSafeMode();
final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
final boolean isSdCardReady = context.registerReceiver(null,
new IntentFilter(StartupReceiver.SYSTEM_READY)) != null;
final boolean isSdCardReady = Utilities.isBootCompleted();
LauncherAppState app = LauncherAppState.getInstance();
InvariantDeviceProfile profile = app.getInvariantDeviceProfile();
@@ -2285,7 +2284,7 @@ public class LauncherModel extends BroadcastReceiver
if (!isSdCardReady && !sPendingPackages.isEmpty()) {
context.registerReceiver(new AppsAvailabilityCheck(),
new IntentFilter(StartupReceiver.SYSTEM_READY),
new IntentFilter(Intent.ACTION_BOOT_COMPLETED),
null, sWorker);
}

View File

@@ -1,15 +0,0 @@
package com.android.launcher3;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class StartupReceiver extends BroadcastReceiver {
static final String SYSTEM_READY = "com.android.launcher3.SYSTEM_READY";
@Override
public void onReceive(Context context, Intent intent) {
context.sendStickyBroadcast(new Intent(SYSTEM_READY));
}
}

View File

@@ -58,6 +58,7 @@ import android.widget.Toast;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Set;
@@ -709,4 +710,18 @@ public final class Utilities {
public static String createDbSelectionQuery(String columnName, Iterable<?> values) {
return String.format(Locale.ENGLISH, "%s IN (%s)", columnName, TextUtils.join(", ", values));
}
@SuppressWarnings({"unchecked", "rawtypes"})
public static boolean isBootCompleted() {
try {
Class clazz = Class.forName("android.os.SystemProperties");
Method getter = clazz.getDeclaredMethod("get", String.class);
String value = (String) getter.invoke(null, "sys.boot_completed");
return "1".equals(value);
} catch (Exception e) {
Log.d(TAG, "Unable to read system properties");
// Assume that boot has completed
return true;
}
}
}

View File

@@ -1,6 +1,7 @@
package com.android.launcher3.compat;
import android.content.Context;
import com.android.launcher3.Utilities;
import java.lang.reflect.Constructor;
@@ -62,6 +63,7 @@ public class AlphabeticIndexCompat extends BaseAlphabeticIndex {
private boolean mHasValidAlphabeticIndex;
private String mDefaultMiscLabel;
@SuppressWarnings({"unchecked", "rawtypes"})
public AlphabeticIndexCompat(Context context) {
super();
try {