android.os.Process#FIRST_APPLICATION_UID源码实例Demo

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

源代码1 项目: android_9.0.0_r45   文件: ProcessRecord.java
public void writeToProto(ProtoOutputStream proto, long fieldId) {
    long token = proto.start(fieldId);
    proto.write(ProcessRecordProto.PID, pid);
    proto.write(ProcessRecordProto.PROCESS_NAME, processName);
    if (info.uid < Process.FIRST_APPLICATION_UID) {
        proto.write(ProcessRecordProto.UID, uid);
    } else {
        proto.write(ProcessRecordProto.USER_ID, userId);
        proto.write(ProcessRecordProto.APP_ID, UserHandle.getAppId(info.uid));
        if (uid != info.uid) {
            proto.write(ProcessRecordProto.ISOLATED_APP_ID, UserHandle.getAppId(uid));
        }
    }
    proto.write(ProcessRecordProto.PERSISTENT, persistent);
    proto.end(token);
}
 
源代码2 项目: android_9.0.0_r45   文件: ProcessRecord.java
void toShortString(StringBuilder sb) {
    sb.append(pid);
    sb.append(':');
    sb.append(processName);
    sb.append('/');
    if (info.uid < Process.FIRST_APPLICATION_UID) {
        sb.append(uid);
    } else {
        sb.append('u');
        sb.append(userId);
        int appId = UserHandle.getAppId(info.uid);
        if (appId >= Process.FIRST_APPLICATION_UID) {
            sb.append('a');
            sb.append(appId - Process.FIRST_APPLICATION_UID);
        } else {
            sb.append('s');
            sb.append(appId);
        }
        if (uid != info.uid) {
            sb.append('i');
            sb.append(UserHandle.getAppId(uid) - Process.FIRST_ISOLATED_UID);
        }
    }
}
 
源代码3 项目: container   文件: VUserHandle.java
public static void formatUid(StringBuilder sb, int uid) {
    if (uid < Process.FIRST_APPLICATION_UID) {
        sb.append(uid);
    } else {
        sb.append('u');
        sb.append(getUserId(uid));
        final int appId = getAppId(uid);
        if (appId >= FIRST_ISOLATED_UID && appId <= LAST_ISOLATED_UID) {
            sb.append('i');
            sb.append(appId - FIRST_ISOLATED_UID);
        } else if (appId >= Process.FIRST_APPLICATION_UID) {
            sb.append('a');
            sb.append(appId - Process.FIRST_APPLICATION_UID);
        } else {
            sb.append('s');
            sb.append(appId);
        }
    }
}
 
源代码4 项目: container   文件: VUserHandle.java
/**
 * Generate a text representation of the vuid, breaking out its individual
 * components -- user, app, isolated, etc.
 * @hide
 */
public static void formatUid(PrintWriter pw, int uid) {
    if (uid < Process.FIRST_APPLICATION_UID) {
        pw.print(uid);
    } else {
        pw.print('u');
        pw.print(getUserId(uid));
        final int appId = getAppId(uid);
        if (appId >= FIRST_ISOLATED_UID && appId <= LAST_ISOLATED_UID) {
            pw.print('i');
            pw.print(appId - FIRST_ISOLATED_UID);
        } else if (appId >= Process.FIRST_APPLICATION_UID) {
            pw.print('a');
            pw.print(appId - Process.FIRST_APPLICATION_UID);
        } else {
            pw.print('s');
            pw.print(appId);
        }
    }
}
 
源代码5 项目: turbo-editor   文件: Common.java
public static Integer getUID(String name) {
	if (name != null) {
		if (name.matches("^[0-9]+$")) {
			return Integer.parseInt(name);
		}
		
		if (UIDS.containsKey(name)) {
			return UIDS.get(name);
			
		} else if (name.startsWith("u")) {
			Integer sep = name.indexOf("_");

			if (sep > 0) {
				Integer uid = Integer.parseInt( name.substring(1, sep) );
				Integer gid = Integer.parseInt( name.substring(sep+2) );
				
				return uid * 100000 + ((Process.FIRST_APPLICATION_UID + gid) % 100000);
			}
		}
	}
	
	return -10000;
}
 
源代码6 项目: android_9.0.0_r45   文件: PowerManagerService.java
private boolean setWakeLockDisabledStateLocked(WakeLock wakeLock) {
    if ((wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK)
            == PowerManager.PARTIAL_WAKE_LOCK) {
        boolean disabled = false;
        final int appid = UserHandle.getAppId(wakeLock.mOwnerUid);
        if (appid >= Process.FIRST_APPLICATION_UID) {
            // Cached inactive processes are never allowed to hold wake locks.
            if (mConstants.NO_CACHED_WAKE_LOCKS) {
                disabled = !wakeLock.mUidState.mActive &&
                        wakeLock.mUidState.mProcState
                                != ActivityManager.PROCESS_STATE_NONEXISTENT &&
                        wakeLock.mUidState.mProcState > ActivityManager.PROCESS_STATE_RECEIVER;
            }
            if (mDeviceIdleMode) {
                // If we are in idle mode, we will also ignore all partial wake locks that are
                // for application uids that are not whitelisted.
                final UidState state = wakeLock.mUidState;
                if (Arrays.binarySearch(mDeviceIdleWhitelist, appid) < 0 &&
                        Arrays.binarySearch(mDeviceIdleTempWhitelist, appid) < 0 &&
                        state.mProcState != ActivityManager.PROCESS_STATE_NONEXISTENT &&
                        state.mProcState >
                                ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE) {
                    disabled = true;
                }
            }
        }
        if (wakeLock.mDisabled != disabled) {
            wakeLock.mDisabled = disabled;
            return true;
        }
    }
    return false;
}
 
源代码7 项目: container   文件: VUserHandle.java
/** @hide */
public static boolean isApp(int uid) {
    if (uid > 0) {
        final int appId = getAppId(uid);
        return appId >= Process.FIRST_APPLICATION_UID && appId <= Process.LAST_APPLICATION_UID;
    } else {
        return false;
    }
}
 
源代码8 项目: container   文件: VUserHandle.java
/**
 * Returns the app id for a given shared app gid.
 * @hide
 */
public static int getAppIdFromSharedAppGid(int gid) {
    final int noUserGid = getAppId(gid);
    if (noUserGid < FIRST_SHARED_APPLICATION_GID ||
            noUserGid > LAST_SHARED_APPLICATION_GID) {
        throw new IllegalArgumentException(Integer.toString(gid) + " is not a shared app gid");
    }
    return (noUserGid + Process.FIRST_APPLICATION_UID) - FIRST_SHARED_APPLICATION_GID;
}
 
源代码9 项目: Study_Android_Demo   文件: SettingsProvider.java
private List<String> getSettingsNamesLocked(int settingsType, int userId) {
    boolean instantApp;
    if (UserHandle.getAppId(Binder.getCallingUid()) < Process.FIRST_APPLICATION_UID) {
        instantApp = false;
    } else {
        ApplicationInfo ai = getCallingApplicationInfoOrThrow();
        instantApp = ai.isInstantApp();
    }
    if (instantApp) {
        return new ArrayList<String>(getInstantAppAccessibleSettings(settingsType));
    } else {
        return mSettingsRegistry.getSettingsNamesLocked(settingsType, userId);
    }
}
 
源代码10 项目: Study_Android_Demo   文件: SettingsProvider.java
private void enforceSettingReadable(String settingName, int settingsType, int userId) {
    if (UserHandle.getAppId(Binder.getCallingUid()) < Process.FIRST_APPLICATION_UID) {
        return;
    }
    ApplicationInfo ai = getCallingApplicationInfoOrThrow();
    if (!ai.isInstantApp()) {
        return;
    }
    if (!getInstantAppAccessibleSettings(settingsType).contains(settingName)
            && !getOverlayInstantAppAccessibleSettings(settingsType).contains(settingName)) {
        throw new SecurityException("Setting " + settingName + " is not accessible from"
                + " ephemeral package " + getCallingPackage());
    }
}
 
源代码11 项目: turbo-editor   文件: Common.java
public static String getUIDName(Integer id) {
	if (UNAMES.containsKey(id)) {
		return UNAMES.get(id);
		
	} else if (id >= 10000) {
		Integer uid = id / 100000;
		Integer gid = id % Process.FIRST_APPLICATION_UID;

		return "u" + uid + "_a" + gid + "";
	}
	
	return null;
}
 
源代码12 项目: deagle   文件: Apps.java
public static boolean isPrivileged(final PackageManager pm, final int uid) {
    if (uid < 0) return false;
    if (uid < Process.FIRST_APPLICATION_UID) return true;
    final String[] pkgs = pm.getPackagesForUid(uid);
    if (pkgs == null) return false;
    for (final String pkg : pkgs) try {
        if (isPrivileged(pm.getApplicationInfo(pkg, 0))) return true;
    } catch (final NameNotFoundException ignored) {}
    return false;
}
 
源代码13 项目: android_9.0.0_r45   文件: Session.java
public Session(WindowManagerService service, IWindowSessionCallback callback,
        IInputMethodClient client, IInputContext inputContext) {
    mService = service;
    mCallback = callback;
    mClient = client;
    mUid = Binder.getCallingUid();
    mPid = Binder.getCallingPid();
    mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
    mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
            INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
    mCanHideNonSystemOverlayWindows = service.mContext.checkCallingOrSelfPermission(
            HIDE_NON_SYSTEM_OVERLAY_WINDOWS) == PERMISSION_GRANTED;
    mCanAcquireSleepToken = service.mContext.checkCallingOrSelfPermission(DEVICE_POWER)
            == PERMISSION_GRANTED;
    mShowingAlertWindowNotificationAllowed = mService.mShowAlertWindowNotifications;
    mDragDropController = mService.mDragDropController;
    StringBuilder sb = new StringBuilder();
    sb.append("Session{");
    sb.append(Integer.toHexString(System.identityHashCode(this)));
    sb.append(" ");
    sb.append(mPid);
    if (mUid < Process.FIRST_APPLICATION_UID) {
        sb.append(":");
        sb.append(mUid);
    } else {
        sb.append(":u");
        sb.append(UserHandle.getUserId(mUid));
        sb.append('a');
        sb.append(UserHandle.getAppId(mUid));
    }
    sb.append("}");
    mStringName = sb.toString();

    synchronized (mService.mWindowMap) {
        if (mService.mInputMethodManager == null && mService.mHaveInputMethods) {
            IBinder b = ServiceManager.getService(
                    Context.INPUT_METHOD_SERVICE);
            mService.mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
        }
    }
    long ident = Binder.clearCallingIdentity();
    try {
        // Note: it is safe to call in to the input method manager
        // here because we are not holding our lock.
        if (mService.mInputMethodManager != null) {
            mService.mInputMethodManager.addClient(client, inputContext,
                    mUid, mPid);
        } else {
            client.setUsingInputMethod(false);
        }
        client.asBinder().linkToDeath(this, 0);
    } catch (RemoteException e) {
        // The caller has died, so we can just forget about this.
        try {
            if (mService.mInputMethodManager != null) {
                mService.mInputMethodManager.removeClient(client);
            }
        } catch (RemoteException ee) {
        }
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
源代码14 项目: android_9.0.0_r45   文件: DeviceIdleController.java
/**
 * Adds an app to the temporary whitelist and resets the endTime for granting the
 * app an exemption to access network and acquire wakelocks.
 */
void addPowerSaveTempWhitelistAppDirectInternal(int callingUid, int appId,
        long duration, boolean sync, String reason) {
    final long timeNow = SystemClock.elapsedRealtime();
    boolean informWhitelistChanged = false;
    synchronized (this) {
        int callingAppId = UserHandle.getAppId(callingUid);
        if (callingAppId >= Process.FIRST_APPLICATION_UID) {
            if (!mPowerSaveWhitelistSystemAppIds.get(callingAppId)) {
                throw new SecurityException("Calling app " + UserHandle.formatUid(callingUid)
                        + " is not on whitelist");
            }
        }
        duration = Math.min(duration, mConstants.MAX_TEMP_APP_WHITELIST_DURATION);
        Pair<MutableLong, String> entry = mTempWhitelistAppIdEndTimes.get(appId);
        final boolean newEntry = entry == null;
        // Set the new end time
        if (newEntry) {
            entry = new Pair<>(new MutableLong(0), reason);
            mTempWhitelistAppIdEndTimes.put(appId, entry);
        }
        entry.first.value = timeNow + duration;
        if (DEBUG) {
            Slog.d(TAG, "Adding AppId " + appId + " to temp whitelist. New entry: " + newEntry);
        }
        if (newEntry) {
            // No pending timeout for the app id, post a delayed message
            try {
                mBatteryStats.noteEvent(BatteryStats.HistoryItem.EVENT_TEMP_WHITELIST_START,
                        reason, appId);
            } catch (RemoteException e) {
            }
            postTempActiveTimeoutMessage(appId, duration);
            updateTempWhitelistAppIdsLocked(appId, true);
            if (sync) {
                informWhitelistChanged = true;
            } else {
                mHandler.obtainMessage(MSG_REPORT_TEMP_APP_WHITELIST_CHANGED, appId, 1)
                        .sendToTarget();
            }
            reportTempWhitelistChangedLocked();
        }
    }
    if (informWhitelistChanged) {
        mNetworkPolicyManagerInternal.onTempPowerSaveWhitelistChange(appId, true);
    }
}
 
源代码15 项目: android_9.0.0_r45   文件: AppErrors.java
void handleShowAppErrorUi(Message msg) {
    AppErrorDialog.Data data = (AppErrorDialog.Data) msg.obj;
    boolean showBackground = Settings.Secure.getInt(mContext.getContentResolver(),
            Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;

    AppErrorDialog dialogToShow = null;
    final String packageName;
    final int userId;
    synchronized (mService) {
        final ProcessRecord proc = data.proc;
        final AppErrorResult res = data.result;
        if (proc == null) {
            Slog.e(TAG, "handleShowAppErrorUi: proc is null");
            return;
        }
        packageName = proc.info.packageName;
        userId = proc.userId;
        if (proc.crashDialog != null) {
            Slog.e(TAG, "App already has crash dialog: " + proc);
            if (res != null) {
                res.set(AppErrorDialog.ALREADY_SHOWING);
            }
            return;
        }
        boolean isBackground = (UserHandle.getAppId(proc.uid)
                >= Process.FIRST_APPLICATION_UID
                && proc.pid != MY_PID);
        for (int profileId : mService.mUserController.getCurrentProfileIds()) {
            isBackground &= (userId != profileId);
        }
        if (isBackground && !showBackground) {
            Slog.w(TAG, "Skipping crash dialog of " + proc + ": background");
            if (res != null) {
                res.set(AppErrorDialog.BACKGROUND_USER);
            }
            return;
        }
        final boolean showFirstCrash = Settings.Global.getInt(
                mContext.getContentResolver(),
                Settings.Global.SHOW_FIRST_CRASH_DIALOG, 0) != 0;
        final boolean showFirstCrashDevOption = Settings.Secure.getIntForUser(
                mContext.getContentResolver(),
                Settings.Secure.SHOW_FIRST_CRASH_DIALOG_DEV_OPTION,
                0,
                mService.mUserController.getCurrentUserId()) != 0;
        final boolean crashSilenced = mAppsNotReportingCrashes != null &&
                mAppsNotReportingCrashes.contains(proc.info.packageName);
        if ((mService.canShowErrorDialogs() || showBackground) && !crashSilenced
                && (showFirstCrash || showFirstCrashDevOption || data.repeating)) {
            proc.crashDialog = dialogToShow = new AppErrorDialog(mContext, mService, data);
        } else {
            // The device is asleep, so just pretend that the user
            // saw a crash dialog and hit "force quit".
            if (res != null) {
                res.set(AppErrorDialog.CANT_SHOW);
            }
        }
    }
    // If we've created a crash dialog, show it without the lock held
    if (dialogToShow != null) {
        Slog.i(TAG, "Showing crash dialog for package " + packageName + " u" + userId);
        dialogToShow.show();
    }
}
 
源代码16 项目: android_9.0.0_r45   文件: WakeupStats.java
/** Update wakeup counters for the given WakeupEvent. */
public void countEvent(WakeupEvent ev) {
    totalWakeups++;
    switch (ev.uid) {
        case Process.ROOT_UID:
            rootWakeups++;
            break;
        case Process.SYSTEM_UID:
            systemWakeups++;
            break;
        case NO_UID:
            noUidWakeups++;
            break;
        default:
            if (ev.uid >= Process.FIRST_APPLICATION_UID) {
                applicationWakeups++;
            } else {
                nonApplicationWakeups++;
            }
            break;
    }

    switch (ev.dstHwAddr.getAddressType()) {
        case MacAddress.TYPE_UNICAST:
            l2UnicastCount++;
            break;
        case MacAddress.TYPE_MULTICAST:
            l2MulticastCount++;
            break;
        case MacAddress.TYPE_BROADCAST:
            l2BroadcastCount++;
            break;
        default:
            break;
    }

    increment(ethertypes, ev.ethertype);
    if (ev.ipNextHeader >= 0) {
        increment(ipNextHeaders, ev.ipNextHeader);
    }
}
 
源代码17 项目: Ezalor   文件: Utils.java
public static boolean isAppProcess() {
    int uid = Process.myUid();
    return uid >= Process.FIRST_APPLICATION_UID && uid <= Process.LAST_APPLICATION_UID;
}
 
源代码18 项目: Study_Android_Demo   文件: SettingsProvider.java
private boolean isNewSsaidSetting(String name) {
    return Settings.Secure.ANDROID_ID.equals(name)
            && UserHandle.getAppId(Binder.getCallingUid()) >= Process.FIRST_APPLICATION_UID;
}
 
源代码19 项目: XPrivacy   文件: PrivacyManager.java
public static boolean isApplication(int uid) {
	uid = Util.getAppId(uid);
	return (uid >= Process.FIRST_APPLICATION_UID && uid <= Process.LAST_APPLICATION_UID);
}