android.os.UserHandle#myUserId ( )源码实例Demo

下面列出了android.os.UserHandle#myUserId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private void onImplicitDirectBoot(int userId) {
    // Only report if someone is relying on implicit behavior while the user
    // is locked; code running when unlocked is going to see both aware and
    // unaware components.
    if (StrictMode.vmImplicitDirectBootEnabled()) {
        // We can cache the unlocked state for the userId we're running as,
        // since any relocking of that user will always result in our
        // process being killed to release any CE FDs we're holding onto.
        if (userId == UserHandle.myUserId()) {
            if (mUserUnlocked) {
                return;
            } else if (mContext.getSystemService(UserManager.class)
                    .isUserUnlockingOrUnlocked(userId)) {
                mUserUnlocked = true;
            } else {
                StrictMode.onImplicitDirectBoot();
            }
        } else if (!mContext.getSystemService(UserManager.class)
                .isUserUnlockingOrUnlocked(userId)) {
            StrictMode.onImplicitDirectBoot();
        }
    }
}
 
public TvRemoteProviderWatcher(Context context, ProviderMethods provider, Handler handler) {
    mContext = context;
    mProvider = provider;
    mHandler = handler;
    mUserId = UserHandle.myUserId();
    mPackageManager = context.getPackageManager();
    mUnbundledServicePackage = context.getString(
            com.android.internal.R.string.config_tvRemoteServicePackage);
}
 
@Override
public boolean onStartJob(JobParameters params) {
    // We need to check the preconditions again because they may not be enforced for
    // subsequent runs.
    if (!isCharging(this) || !isDumpsysTaskEnabled(getContentResolver())) {
        jobFinished(params, true);
        return false;
    }


    VolumeInfo volume = getPackageManager().getPrimaryStorageCurrentVolume();
    // volume is null if the primary storage is not yet mounted.
    if (volume == null) {
        return false;
    }
    AppCollector collector = new AppCollector(this, volume);

    final int userId = UserHandle.myUserId();
    UserEnvironment environment = new UserEnvironment(userId);
    LogRunnable task = new LogRunnable();
    task.setDownloadsDirectory(
            environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS));
    task.setSystemSize(FileCollector.getSystemSize(this));
    task.setLogOutputFile(new File(DUMPSYS_CACHE_PATH));
    task.setAppCollector(collector);
    task.setJobService(this, params);
    task.setContext(this);
    AsyncTask.execute(task);
    return true;
}
 
源代码4 项目: android_9.0.0_r45   文件: InputContentInfo.java
/**
 * @return Content URI with which the content can be obtained.
 */
@NonNull
public Uri getContentUri() {
    // Fix up the content URI when and only when the caller's user ID does not match the owner's
    // user ID.
    if (mContentUriOwnerUserId != UserHandle.myUserId()) {
        return ContentProvider.maybeAddUserId(mContentUri, mContentUriOwnerUserId);
    }
    return mContentUri;
}
 
源代码5 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object createService(ContextImpl ctx) {
    IBinder iBinder = ServiceManager.getService(Context.PRINT_SERVICE);
    IPrintManager service = IPrintManager.Stub.asInterface(iBinder);
    return new PrintManager(ctx.getOuterContext(), service, UserHandle.myUserId(),
            UserHandle.getAppId(Process.myUid()));
}
 
源代码6 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object createService(ContextImpl ctx) {
    IBinder iBinder = ServiceManager.getService(TV_INPUT_SERVICE);
    ITvInputManager service = ITvInputManager.Stub.asInterface(iBinder);
    return new TvInputManager(service, UserHandle.myUserId());
}
 
源代码7 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object createService(ContextImpl ctx) {
    IBinder iBinder = ServiceManager.getService(Context.PRINT_SERVICE);
    IPrintManager service = IPrintManager.Stub.asInterface(iBinder);
    return new PrintManager(ctx.getOuterContext(), service, UserHandle.myUserId(),
            UserHandle.getAppId(Process.myUid()));
}
 
源代码8 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object createService(ContextImpl ctx) {
    IBinder iBinder = ServiceManager.getService(TV_INPUT_SERVICE);
    ITvInputManager service = ITvInputManager.Stub.asInterface(iBinder);
    return new TvInputManager(service, UserHandle.myUserId());
}
 
源代码9 项目: AndroidComponentPlugin   文件: ContextImpl.java
public Object createService(ContextImpl ctx) {
    IBinder iBinder = ServiceManager.getService(Context.PRINT_SERVICE);
    IPrintManager service = IPrintManager.Stub.asInterface(iBinder);
    return new PrintManager(ctx.getOuterContext(), service, UserHandle.myUserId(),
            UserHandle.getAppId(Process.myUid()));
}
 
源代码10 项目: android_9.0.0_r45   文件: PackageStats.java
public PackageStats(String pkgName) {
    packageName = pkgName;
    userHandle = UserHandle.myUserId();
}
 
源代码11 项目: android_9.0.0_r45   文件: LauncherApps.java
/**
 * Show an error log on logcat, when the calling user is a managed profile, and the target
 * user is different from the calling user, in order to help developers to detect it.
 */
private void logErrorForInvalidProfileAccess(@NonNull UserHandle target) {
    if (UserHandle.myUserId() != target.getIdentifier() && mUserManager.isManagedProfile()) {
        Log.w(TAG, "Accessing other profiles/users from managed profile is no longer allowed.");
    }
}