下面列出了android.app.usage.NetworkStatsManager#com.android.server.LocalServices 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* @return true if camera was launched, false otherwise.
*/
@VisibleForTesting
boolean handleCameraGesture(boolean useWakelock, int source) {
boolean userSetupComplete = Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
if (!userSetupComplete) {
if (DBG) Slog.d(TAG, String.format(
"userSetupComplete = %s, ignoring camera gesture.",
userSetupComplete));
return false;
}
if (DBG) Slog.d(TAG, String.format(
"userSetupComplete = %s, performing camera gesture.",
userSetupComplete));
if (useWakelock) {
// Make sure we don't sleep too early
mWakeLock.acquire(500L);
}
StatusBarManagerInternal service = LocalServices.getService(
StatusBarManagerInternal.class);
service.onCameraLaunchGestureDetected(source);
return true;
}
private void pullMobileBytesTransfer(int tagId, List<StatsLogEventWrapper> pulledData) {
long token = Binder.clearCallingIdentity();
try {
BatteryStatsInternal bs = LocalServices.getService(BatteryStatsInternal.class);
String[] ifaces = bs.getMobileIfaces();
if (ifaces.length == 0) {
return;
}
NetworkStatsFactory nsf = new NetworkStatsFactory();
// Combine all the metrics per Uid into one record.
NetworkStats stats =
nsf.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, NetworkStats.TAG_NONE, null)
.groupedByUid();
addNetworkStats(tagId, pulledData, stats, false);
} catch (java.io.IOException e) {
Slog.e(TAG, "Pulling netstats for mobile bytes has error", e);
} finally {
Binder.restoreCallingIdentity(token);
}
}
/**
* Method to start lock task mode on a given task.
*
* @param task the task that should be locked.
* @param isSystemCaller indicates whether this request was initiated by the system via
* {@link ActivityManagerService#startSystemLockTaskMode(int)}. If
* {@code true}, this intends to start pinned mode; otherwise, we look
* at the calling task's mLockTaskAuth to decide which mode to start.
* @param callingUid the caller that requested the launch of lock task mode.
*/
void startLockTaskMode(@NonNull TaskRecord task, boolean isSystemCaller, int callingUid) {
if (!isSystemCaller) {
task.mLockTaskUid = callingUid;
if (task.mLockTaskAuth == LOCK_TASK_AUTH_PINNABLE) {
// startLockTask() called by app, but app is not part of lock task whitelist. Show
// app pinning request. We will come back here with isSystemCaller true.
if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Mode default, asking user");
StatusBarManagerInternal statusBarManager = LocalServices.getService(
StatusBarManagerInternal.class);
if (statusBarManager != null) {
statusBarManager.showScreenPinningRequest(task.taskId);
}
return;
}
}
// System can only initiate screen pinning, not full lock task mode
if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK,
isSystemCaller ? "Locking pinned" : "Locking fully");
setLockTaskMode(task, isSystemCaller ? LOCK_TASK_MODE_PINNED : LOCK_TASK_MODE_LOCKED,
"startLockTask", true);
}
void broadcastDragStartedLocked(final float touchX, final float touchY) {
mOriginalX = mCurrentX = touchX;
mOriginalY = mCurrentY = touchY;
// Cache a base-class instance of the clip metadata so that parceling
// works correctly in calling out to the apps.
mDataDescription = (mData != null) ? mData.getDescription() : null;
mNotifiedWindows.clear();
mDragInProgress = true;
mSourceUserId = UserHandle.getUserId(mUid);
final UserManagerInternal userManager = LocalServices.getService(UserManagerInternal.class);
mCrossProfileCopyAllowed = !userManager.getUserRestriction(
mSourceUserId, UserManager.DISALLOW_CROSS_PROFILE_COPY_PASTE);
if (DEBUG_DRAG) {
Slog.d(TAG_WM, "broadcasting DRAG_STARTED at (" + touchX + ", " + touchY + ")");
}
mDisplayContent.forAllWindows(w -> {
sendDragStartedLocked(w, touchX, touchY, mDataDescription);
}, false /* traverseTopToBottom */ );
}
@Override
public void onUserInteractionStarted(String packageName, int userId) {
final int uid = mLocalPM.getPackageUid(packageName,
PackageManager.MATCH_UNINSTALLED_PACKAGES, userId);
if (uid < 0) {
// Quietly ignore; the case is already logged elsewhere
return;
}
long sinceLast = mUsageStats.getTimeSinceLastJobRun(packageName, userId);
if (sinceLast > 2 * DateUtils.DAY_IN_MILLIS) {
// Too long ago, not worth logging
sinceLast = 0L;
}
final DeferredJobCounter counter = new DeferredJobCounter();
synchronized (mLock) {
mJobs.forEachJobForSourceUid(uid, counter);
}
if (counter.numDeferred() > 0 || sinceLast > 0) {
BatteryStatsInternal mBatteryStatsInternal = LocalServices.getService
(BatteryStatsInternal.class);
mBatteryStatsInternal.noteJobsDeferred(uid, counter.numDeferred(), sinceLast);
}
}
BatteryStatsService(Context context, File systemDir, Handler handler) {
// BatteryStatsImpl expects the ActivityManagerService handler, so pass that one through.
mContext = context;
mUserManagerUserInfoProvider = new BatteryStatsImpl.UserInfoProvider() {
private UserManagerInternal umi;
@Override
public int[] getUserIds() {
if (umi == null) {
umi = LocalServices.getService(UserManagerInternal.class);
}
return (umi != null) ? umi.getUserIds() : null;
}
};
mStats = new BatteryStatsImpl(systemDir, handler, this, mUserManagerUserInfoProvider);
mWorker = new BatteryExternalStatsWorker(context, mStats);
mStats.setExternalStatsSyncLocked(mWorker);
mStats.setRadioScanningTimeoutLocked(mContext.getResources().getInteger(
com.android.internal.R.integer.config_radioScanningTimeout) * 1000L);
mStats.setPowerProfileLocked(new PowerProfile(context));
}
public void startTracking() {
IntentFilter filter = new IntentFilter();
// Battery health.
filter.addAction(Intent.ACTION_BATTERY_LOW);
filter.addAction(Intent.ACTION_BATTERY_OKAY);
// Charging/not charging.
filter.addAction(BatteryManager.ACTION_CHARGING);
filter.addAction(BatteryManager.ACTION_DISCHARGING);
mContext.registerReceiver(this, filter);
// Initialise tracker state.
BatteryManagerInternal batteryManagerInternal =
LocalServices.getService(BatteryManagerInternal.class);
mBatteryHealthy = !batteryManagerInternal.getBatteryLevelLow();
mCharging = batteryManagerInternal.isPowered(BatteryManager.BATTERY_PLUGGED_ANY);
}
private ArrayList<ResolveInfo> createFilterdResolveInfoList(List<ResolveInfo> list) {
if (list == null) {
return null;
}
final ArrayList<ResolveInfo> resultList = new ArrayList<>(list.size());
final PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
final int callingUid = Binder.getCallingUid();
final int callingUserId = UserHandle.getCallingUserId();
for (ResolveInfo info : list) {
if (pm.canAccessComponent(
callingUid, info.activityInfo.getComponentName(), callingUserId)) {
resultList.add(info);
}
}
return resultList;
}
/** Do not hold any of the locks from this service when calling. */
private boolean shouldCacheSpForUser(@UserIdInt int userId) {
// Before the user setup has completed, an admin could be installed that requires the SP to
// be cached (see below).
if (Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.USER_SETUP_COMPLETE, 0, userId) == 0) {
return true;
}
// If the user has an admin which can perform an untrusted credential reset, the SP needs to
// be cached. If there isn't a DevicePolicyManager then there can't be an admin in the first
// place so caching is not necessary.
final DevicePolicyManagerInternal dpmi = LocalServices.getService(
DevicePolicyManagerInternal.class);
if (dpmi == null) {
return false;
}
return dpmi.canUserHaveUntrustedCredentialReset(userId);
}
private void pullWifiBytesTransfer(int tagId, List<StatsLogEventWrapper> pulledData) {
long token = Binder.clearCallingIdentity();
try {
// TODO: Consider caching the following call to get BatteryStatsInternal.
BatteryStatsInternal bs = LocalServices.getService(BatteryStatsInternal.class);
String[] ifaces = bs.getWifiIfaces();
if (ifaces.length == 0) {
return;
}
NetworkStatsFactory nsf = new NetworkStatsFactory();
// Combine all the metrics per Uid into one record.
NetworkStats stats =
nsf.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, NetworkStats.TAG_NONE, null)
.groupedByUid();
addNetworkStats(tagId, pulledData, stats, false);
} catch (java.io.IOException e) {
Slog.e(TAG, "Pulling netstats for wifi bytes has error", e);
} finally {
Binder.restoreCallingIdentity(token);
}
}
public DefaultPermissionGrantPolicy(Context context, Looper looper,
@Nullable DefaultPermissionGrantedCallback callback,
@NonNull PermissionManagerService permissionManager) {
mContext = context;
mHandler = new Handler(looper) {
@Override
public void handleMessage(Message msg) {
if (msg.what == MSG_READ_DEFAULT_PERMISSION_EXCEPTIONS) {
synchronized (mLock) {
if (mGrantExceptions == null) {
mGrantExceptions = readDefaultPermissionExceptionsLocked();
}
}
}
}
};
mPermissionGrantedCallback = callback;
mPermissionManager = permissionManager;
mServiceInternal = LocalServices.getService(PackageManagerInternal.class);
}
private UserManagerService(Context context, PackageManagerService pm,
UserDataPreparer userDataPreparer, Object packagesLock, File dataDir) {
mContext = context;
mPm = pm;
mPackagesLock = packagesLock;
mHandler = new MainHandler();
mUserDataPreparer = userDataPreparer;
synchronized (mPackagesLock) {
mUsersDir = new File(dataDir, USER_INFO_DIR);
mUsersDir.mkdirs();
// Make zeroth user directory, for services to migrate their files to that location
File userZeroDir = new File(mUsersDir, String.valueOf(UserHandle.USER_SYSTEM));
userZeroDir.mkdirs();
FileUtils.setPermissions(mUsersDir.toString(),
FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IROTH | FileUtils.S_IXOTH,
-1, -1);
mUserListFile = new File(mUsersDir, USER_LIST_FILENAME);
initDefaultGuestRestrictions();
readUserListLP();
sInstance = this;
}
mLocalService = new LocalService();
LocalServices.addService(UserManagerInternal.class, mLocalService);
mLockPatternUtils = new LockPatternUtils(mContext);
mUserStates.put(UserHandle.USER_SYSTEM, UserState.STATE_BOOTING);
}
public NotificationRecord(Context context, StatusBarNotification sbn,
NotificationChannel channel) {
this.sbn = sbn;
mTargetSdkVersion = LocalServices.getService(PackageManagerInternal.class)
.getPackageTargetSdkVersion(sbn.getPackageName());
mAm = ActivityManager.getService();
mOriginalFlags = sbn.getNotification().flags;
mRankingTimeMs = calculateRankingTimeMs(0L);
mCreationTimeMs = sbn.getPostTime();
mUpdateTimeMs = mCreationTimeMs;
mInterruptionTimeMs = mCreationTimeMs;
mContext = context;
stats = new NotificationUsageStats.SingleNotificationStats();
mChannel = channel;
mPreChannelsNotification = isPreChannelsNotification();
mSound = calculateSound();
mVibration = calculateVibration();
mAttributes = calculateAttributes();
mImportance = calculateImportance();
mLight = calculateLights();
mAdjustments = new ArrayList<>();
mStats = new NotificationStats();
calculateUserSentiment();
calculateGrantableUris();
}
@Override
public ActivityInfo resolveActivity(
String callingPackage, ComponentName component, UserHandle user)
throws RemoteException {
if (!canAccessProfile(user.getIdentifier(), "Cannot resolve activity")) {
return null;
}
final int callingUid = injectBinderCallingUid();
long ident = Binder.clearCallingIdentity();
try {
final PackageManagerInternal pmInt =
LocalServices.getService(PackageManagerInternal.class);
return pmInt.getActivityInfo(component,
PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
callingUid, user.getIdentifier());
} finally {
Binder.restoreCallingIdentity(ident);
}
}
private ParceledListSlice<ResolveInfo> queryActivitiesForUser(String callingPackage,
Intent intent, UserHandle user) {
if (!canAccessProfile(user.getIdentifier(), "Cannot retrieve activities")) {
return null;
}
final int callingUid = injectBinderCallingUid();
long ident = injectClearCallingIdentity();
try {
final PackageManagerInternal pmInt =
LocalServices.getService(PackageManagerInternal.class);
List<ResolveInfo> apps = pmInt.queryIntentActivities(intent,
PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
callingUid, user.getIdentifier());
return new ParceledListSlice<>(apps);
} finally {
injectRestoreCallingIdentity(ident);
}
}
@VisibleForTesting
NetworkStatsService(Context context, INetworkManagementService networkManager,
AlarmManager alarmManager, PowerManager.WakeLock wakeLock, Clock clock,
TelephonyManager teleManager, NetworkStatsSettings settings,
NetworkStatsObservers statsObservers, File systemDir, File baseDir) {
mContext = checkNotNull(context, "missing Context");
mNetworkManager = checkNotNull(networkManager, "missing INetworkManagementService");
mAlarmManager = checkNotNull(alarmManager, "missing AlarmManager");
mClock = checkNotNull(clock, "missing Clock");
mSettings = checkNotNull(settings, "missing NetworkStatsSettings");
mTeleManager = checkNotNull(teleManager, "missing TelephonyManager");
mWakeLock = checkNotNull(wakeLock, "missing WakeLock");
mStatsObservers = checkNotNull(statsObservers, "missing NetworkStatsObservers");
mSystemDir = checkNotNull(systemDir, "missing systemDir");
mBaseDir = checkNotNull(baseDir, "missing baseDir");
mUseBpfTrafficStats = new File("/sys/fs/bpf/traffic_uid_stats_map").exists();
LocalServices.addService(NetworkStatsManagerInternal.class,
new NetworkStatsManagerInternalImpl());
}
@Override
public ApplicationInfo getApplicationInfo(
String callingPackage, String packageName, int flags, UserHandle user)
throws RemoteException {
if (!canAccessProfile(user.getIdentifier(), "Cannot check package")) {
return null;
}
final int callingUid = injectBinderCallingUid();
long ident = Binder.clearCallingIdentity();
try {
final PackageManagerInternal pmInt =
LocalServices.getService(PackageManagerInternal.class);
ApplicationInfo info = pmInt.getApplicationInfo(packageName, flags,
callingUid, user.getIdentifier());
return info;
} finally {
Binder.restoreCallingIdentity(ident);
}
}
@Override
public boolean isActivityEnabled(
String callingPackage, ComponentName component, UserHandle user)
throws RemoteException {
if (!canAccessProfile(user.getIdentifier(), "Cannot check component")) {
return false;
}
final int callingUid = injectBinderCallingUid();
long ident = Binder.clearCallingIdentity();
try {
final PackageManagerInternal pmInt =
LocalServices.getService(PackageManagerInternal.class);
ActivityInfo info = pmInt.getActivityInfo(component,
PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
callingUid, user.getIdentifier());
return info != null;
} finally {
Binder.restoreCallingIdentity(ident);
}
}
private boolean interceptSuspendedByAdminPackage() {
DevicePolicyManagerInternal devicePolicyManager = LocalServices
.getService(DevicePolicyManagerInternal.class);
if (devicePolicyManager == null) {
return false;
}
mIntent = devicePolicyManager.createShowAdminSupportIntent(mUserId, true);
mIntent.putExtra(EXTRA_RESTRICTION, POLICY_SUSPEND_PACKAGES);
mCallingPid = mRealCallingPid;
mCallingUid = mRealCallingUid;
mResolvedType = null;
final UserInfo parent = mUserManager.getProfileParent(mUserId);
if (parent != null) {
mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, parent.id, 0,
mRealCallingUid);
} else {
mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, mUserId, 0,
mRealCallingUid);
}
mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/);
return true;
}
public int canRestoreTo(ShortcutService s, PackageInfo currentPackage, boolean anyVersionOkay) {
PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class);
if (!BackupUtils.signaturesMatch(mSigHashes, currentPackage, pmi)) {
Slog.w(TAG, "Can't restore: Package signature mismatch");
return ShortcutInfo.DISABLED_REASON_SIGNATURE_MISMATCH;
}
if (!ShortcutService.shouldBackupApp(currentPackage) || !mBackupSourceBackupAllowed) {
// "allowBackup" was true when backed up, but now false.
Slog.w(TAG, "Can't restore: package didn't or doesn't allow backup");
return ShortcutInfo.DISABLED_REASON_BACKUP_NOT_SUPPORTED;
}
if (!anyVersionOkay && (currentPackage.getLongVersionCode() < mBackupSourceVersionCode)) {
Slog.w(TAG, String.format(
"Can't restore: package current version %d < backed up version %d",
currentPackage.getLongVersionCode(), mBackupSourceVersionCode));
return ShortcutInfo.DISABLED_REASON_VERSION_LOWER;
}
return ShortcutInfo.DISABLED_REASON_NOT_DISABLED;
}
public PackageInstallerService(Context context, PackageManagerService pm) {
mContext = context;
mPm = pm;
mPermissionManager = LocalServices.getService(PermissionManagerInternal.class);
mInstallThread = new HandlerThread(TAG);
mInstallThread.start();
mInstallHandler = new Handler(mInstallThread.getLooper());
mCallbacks = new Callbacks(mInstallThread.getLooper());
mSessionsFile = new AtomicFile(
new File(Environment.getDataSystemDirectory(), "install_sessions.xml"),
"package-session");
mSessionsDir = new File(Environment.getDataSystemDirectory(), "install_sessions");
mSessionsDir.mkdirs();
}
@Override
public void setVrInputMethod(ComponentName componentName) {
enforceCallerPermissionAnyOf(Manifest.permission.RESTRICTED_VR_ACCESS);
InputMethodManagerInternal imm =
LocalServices.getService(InputMethodManagerInternal.class);
imm.startVrInputMethodNoCheck(componentName);
}
/**
* @hide
*/
public static boolean isSystemReady() {
if (!sSystemReady) {
if (ActivityThread.isSystem()) {
sSystemReady =
LocalServices.getService(ActivityManagerInternal.class).isSystemReady();
} else {
// Since this is being called from outside system server, system should be
// ready by now.
sSystemReady = true;
}
}
return sSystemReady;
}
ContentService(Context context, boolean factoryTest) {
mContext = context;
mFactoryTest = factoryTest;
// Let the package manager query for the sync adapters for a given authority
// as we grant default permissions to sync adapters for specific authorities.
PackageManagerInternal packageManagerInternal = LocalServices.getService(
PackageManagerInternal.class);
packageManagerInternal.setSyncAdapterPackagesprovider(
new PackageManagerInternal.SyncAdapterPackagesProvider() {
@Override
public String[] getPackages(String authority, int userId) {
return getSyncAdapterPackagesForAuthorityAsUser(authority, userId);
}
});
final IntentFilter packageFilter = new IntentFilter();
packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
packageFilter.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
packageFilter.addDataScheme("package");
mContext.registerReceiverAsUser(mCacheReceiver, UserHandle.ALL,
packageFilter, null, null);
final IntentFilter localeFilter = new IntentFilter();
localeFilter.addAction(Intent.ACTION_LOCALE_CHANGED);
mContext.registerReceiverAsUser(mCacheReceiver, UserHandle.ALL,
localeFilter, null, null);
}
/**
* Register a content observer tied to a specific user's view of the provider.
* @param userHandle the user whose view of the provider is to be observed. May be
* the calling user without requiring any permission, otherwise the caller needs to
* hold the INTERACT_ACROSS_USERS_FULL permission or hold a read uri grant to the uri.
* Pseudousers USER_ALL and USER_CURRENT are properly handled; all other pseudousers
* are forbidden.
*/
@Override
public void registerContentObserver(Uri uri, boolean notifyForDescendants,
IContentObserver observer, int userHandle, int targetSdkVersion) {
if (observer == null || uri == null) {
throw new IllegalArgumentException("You must pass a valid uri and observer");
}
final int uid = Binder.getCallingUid();
final int pid = Binder.getCallingPid();
userHandle = handleIncomingUser(uri, pid, uid,
Intent.FLAG_GRANT_READ_URI_PERMISSION, true, userHandle);
final String msg = LocalServices.getService(ActivityManagerInternal.class)
.checkContentProviderAccess(uri.getAuthority(), userHandle);
if (msg != null) {
if (targetSdkVersion >= Build.VERSION_CODES.O) {
throw new SecurityException(msg);
} else {
if (msg.startsWith("Failed to find provider")) {
// Sigh, we need to quietly let apps targeting older API
// levels notify on non-existent providers.
} else {
Log.w(TAG, "Ignoring content changes for " + uri + " from " + uid + ": " + msg);
return;
}
}
}
synchronized (mRootNode) {
mRootNode.addObserverLocked(uri, observer, notifyForDescendants, mRootNode,
uid, pid, userHandle);
if (false) Log.v(TAG, "Registered observer " + observer + " at " + uri +
" with notifyForDescendants " + notifyForDescendants);
}
}
@SyncExemption
private int getSyncExemptionAndCleanUpExtrasForCaller(int callingUid, Bundle extras) {
if (extras != null) {
final int exemption =
extras.getInt(ContentResolver.SYNC_VIRTUAL_EXTRAS_EXEMPTION_FLAG, -1);
// Need to remove the virtual extra.
extras.remove(ContentResolver.SYNC_VIRTUAL_EXTRAS_EXEMPTION_FLAG);
if (exemption != -1) {
return exemption;
}
}
final ActivityManagerInternal ami =
LocalServices.getService(ActivityManagerInternal.class);
if (ami == null) {
return ContentResolver.SYNC_EXEMPTION_NONE;
}
final int procState = ami.getUidProcessState(callingUid);
final boolean isUidActive = ami.isUidActive(callingUid);
// Providers bound by a TOP app will get PROCESS_STATE_BOUND_TOP, so include those as well
if (procState <= ActivityManager.PROCESS_STATE_TOP
|| procState == ActivityManager.PROCESS_STATE_BOUND_TOP) {
return ContentResolver.SYNC_EXEMPTION_PROMOTE_BUCKET_WITH_TEMP;
}
if (procState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND || isUidActive) {
return ContentResolver.SYNC_EXEMPTION_PROMOTE_BUCKET;
}
return ContentResolver.SYNC_EXEMPTION_NONE;
}
private void setSaturationLevelInternal(float level) {
if (level < 0 || level > 1) {
throw new IllegalArgumentException("Saturation level must be between 0 and 1");
}
float[] matrix = (level == 1.0f ? null : computeSaturationMatrix(level));
DisplayTransformManager dtm = LocalServices.getService(DisplayTransformManager.class);
dtm.setColorMatrix(DisplayTransformManager.LEVEL_COLOR_MATRIX_SATURATION, matrix);
}
private void startServiceInBackgroundAsUser(final Intent intent, final UserHandle user) {
if (intent.getComponent() == null) {
return;
}
final String packageName = intent.getComponent().getPackageName();
final DeviceIdleController.LocalService idleController =
LocalServices.getService(DeviceIdleController.LocalService.class);
idleController.addPowerSaveTempWhitelistApp(Process.myUid(), packageName,
KEYCHAIN_IDLE_WHITELIST_DURATION_MS, user.getIdentifier(), false, "keychain");
getContext().startServiceAsUser(intent, user);
}
/**
* Called when ActivityManagerService receives its systemReady call during boot.
*/
public void onSystemReady() {
VrManagerInternal vrManagerInternal = LocalServices.getService(VrManagerInternal.class);
if (vrManagerInternal != null) {
vrManagerInternal.addPersistentVrModeStateListener(mPersistentVrModeListener);
}
}
/**
* @hide
*/
public static boolean isSystemReady() {
if (!sSystemReady) {
if (ActivityThread.isSystem()) {
sSystemReady =
LocalServices.getService(ActivityManagerInternal.class).isSystemReady();
} else {
// Since this is being called from outside system server, system should be
// ready by now.
sSystemReady = true;
}
}
return sSystemReady;
}