Java Code Examples for android.os.UserHandle#formatUid()

The following examples show how to use android.os.UserHandle#formatUid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IdleController.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void dumpControllerStateLocked(IndentingPrintWriter pw,
        Predicate<JobStatus> predicate) {
    pw.println("Currently idle: " + mIdleTracker.isIdle());
    pw.println();

    for (int i = 0; i < mTrackedTasks.size(); i++) {
        final JobStatus js = mTrackedTasks.valueAt(i);
        if (!predicate.test(js)) {
            continue;
        }
        pw.print("#");
        js.printUniqueId(pw);
        pw.print(" from ");
        UserHandle.formatUid(pw, js.getSourceUid());
        pw.println();
    }
}
 
Example 2
Source File: BroadcastQueue.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
final void scheduleTempWhitelistLocked(int uid, long duration, BroadcastRecord r) {
    if (duration > Integer.MAX_VALUE) {
        duration = Integer.MAX_VALUE;
    }
    // XXX ideally we should pause the broadcast until everything behind this is done,
    // or else we will likely start dispatching the broadcast before we have opened
    // access to the app (there is a lot of asynchronicity behind this).  It is probably
    // not that big a deal, however, because the main purpose here is to allow apps
    // to hold wake locks, and they will be able to acquire their wake lock immediately
    // it just won't be enabled until we get through this work.
    StringBuilder b = new StringBuilder();
    b.append("broadcast:");
    UserHandle.formatUid(b, r.callingUid);
    b.append(":");
    if (r.intent.getAction() != null) {
        b.append(r.intent.getAction());
    } else if (r.intent.getComponent() != null) {
        r.intent.getComponent().appendShortString(b);
    } else if (r.intent.getData() != null) {
        b.append(r.intent.getData());
    }
    mService.tempWhitelistUidLocked(uid, duration, b.toString());
}
 
Example 3
Source File: BroadcastQueue.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
final void scheduleTempWhitelistLocked(int uid, long duration, BroadcastRecord r) {
    if (duration > Integer.MAX_VALUE) {
        duration = Integer.MAX_VALUE;
    }
    // XXX ideally we should pause the broadcast until everything behind this is done,
    // or else we will likely start dispatching the broadcast before we have opened
    // access to the app (there is a lot of asynchronicity behind this).  It is probably
    // not that big a deal, however, because the main purpose here is to allow apps
    // to hold wake locks, and they will be able to acquire their wake lock immediately
    // it just won't be enabled until we get through this work.
    StringBuilder b = new StringBuilder();
    b.append("broadcast:");
    UserHandle.formatUid(b, r.callingUid);
    b.append(":");
    if (r.intent.getAction() != null) {
        b.append(r.intent.getAction());
    } else if (r.intent.getComponent() != null) {
        r.intent.getComponent().appendShortString(b);
    } else if (r.intent.getData() != null) {
        b.append(r.intent.getData());
    }
    mService.tempWhitelistUidLocked(uid, duration, b.toString());
}
 
Example 4
Source File: StorageController.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void dumpControllerStateLocked(IndentingPrintWriter pw,
        Predicate<JobStatus> predicate) {
    pw.println("Not low: " + mStorageTracker.isStorageNotLow());
    pw.println("Sequence: " + mStorageTracker.getSeq());
    pw.println();

    for (int i = 0; i < mTrackedTasks.size(); i++) {
        final JobStatus js = mTrackedTasks.valueAt(i);
        if (!predicate.test(js)) {
            continue;
        }
        pw.print("#");
        js.printUniqueId(pw);
        pw.print(" from ");
        UserHandle.formatUid(pw, js.getSourceUid());
        pw.println();
    }
}
 
Example 5
Source File: BatteryController.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void dumpControllerStateLocked(IndentingPrintWriter pw,
        Predicate<JobStatus> predicate) {
    pw.println("Stable power: " + mChargeTracker.isOnStablePower());
    pw.println("Not low: " + mChargeTracker.isBatteryNotLow());

    if (mChargeTracker.isMonitoring()) {
        pw.print("MONITORING: seq=");
        pw.println(mChargeTracker.getSeq());
    }
    pw.println();

    for (int i = 0; i < mTrackedTasks.size(); i++) {
        final JobStatus js = mTrackedTasks.valueAt(i);
        if (!predicate.test(js)) {
            continue;
        }
        pw.print("#");
        js.printUniqueId(pw);
        pw.print(" from ");
        UserHandle.formatUid(pw, js.getSourceUid());
        pw.println();
    }
}
 
Example 6
Source File: ConnectivityController.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@GuardedBy("mLock")
@Override
public void dumpControllerStateLocked(IndentingPrintWriter pw,
        Predicate<JobStatus> predicate) {
    for (int i = 0; i < mTrackedJobs.size(); i++) {
        final JobStatus js = mTrackedJobs.valueAt(i);
        if (predicate.test(js)) {
            pw.print("#");
            js.printUniqueId(pw);
            pw.print(" from ");
            UserHandle.formatUid(pw, js.getSourceUid());
            pw.print(": ");
            pw.print(js.getJob().getRequiredNetwork());
            pw.println();
        }
    }
}
 
Example 7
Source File: AppOpsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
    StringBuilder sb = new StringBuilder(128);
    sb.append("ModeCallback{");
    sb.append(Integer.toHexString(System.identityHashCode(this)));
    sb.append(" watchinguid=");
    UserHandle.formatUid(sb, mWatchingUid);
    sb.append(" flags=0x");
    sb.append(Integer.toHexString(mFlags));
    sb.append(" from uid=");
    UserHandle.formatUid(sb, mCallingUid);
    sb.append(" pid=");
    sb.append(mCallingPid);
    sb.append('}');
    return sb.toString();
}
 
Example 8
Source File: VoiceInteractionSession.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
    writer.print(prefix); writer.print("mInterface=");
    writer.println(mInterface.asBinder());
    writer.print(prefix); writer.print("mCallingPackage="); writer.print(mCallingPackage);
    writer.print(" mCallingUid="); UserHandle.formatUid(writer, mCallingUid);
    writer.println();
    writer.print(prefix); writer.print("mCallback=");
    writer.println(mCallback.asBinder());
    if (mExtras != null) {
        writer.print(prefix); writer.print("mExtras=");
        writer.println(mExtras);
    }
}
 
Example 9
Source File: VoiceInteractionSession.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    StringBuilder sb = new StringBuilder(128);
    DebugUtils.buildShortClassTag(this, sb);
    sb.append(" ");
    sb.append(mInterface.asBinder());
    sb.append(" pkg=");
    sb.append(mCallingPackage);
    sb.append(" uid=");
    UserHandle.formatUid(sb, mCallingUid);
    sb.append('}');
    return sb.toString();
}
 
Example 10
Source File: AppOpsService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    StringBuilder sb = new StringBuilder(128);
    sb.append("ActiveCallback{");
    sb.append(Integer.toHexString(System.identityHashCode(this)));
    sb.append(" watchinguid=");
    UserHandle.formatUid(sb, mWatchingUid);
    sb.append(" from uid=");
    UserHandle.formatUid(sb, mCallingUid);
    sb.append(" pid=");
    sb.append(mCallingPid);
    sb.append('}');
    return sb.toString();
}
 
Example 11
Source File: TimeController.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void dumpControllerStateLocked(IndentingPrintWriter pw,
        Predicate<JobStatus> predicate) {
    final long nowElapsed = sElapsedRealtimeClock.millis();
    pw.println("Elapsed clock: " + nowElapsed);

    pw.print("Next delay alarm in ");
    TimeUtils.formatDuration(mNextDelayExpiredElapsedMillis, nowElapsed, pw);
    pw.println();
    pw.print("Next deadline alarm in ");
    TimeUtils.formatDuration(mNextJobExpiredElapsedMillis, nowElapsed, pw);
    pw.println();
    pw.println();

    for (JobStatus ts : mTrackedJobs) {
        if (!predicate.test(ts)) {
            continue;
        }
        pw.print("#");
        ts.printUniqueId(pw);
        pw.print(" from ");
        UserHandle.formatUid(pw, ts.getSourceUid());
        pw.print(": Delay=");
        if (ts.hasTimingDelayConstraint()) {
            TimeUtils.formatDuration(ts.getEarliestRunTime(), nowElapsed, pw);
        } else {
            pw.print("N/A");
        }
        pw.print(", Deadline=");
        if (ts.hasDeadlineConstraint()) {
            TimeUtils.formatDuration(ts.getLatestRunTimeElapsed(), nowElapsed, pw);
        } else {
            pw.print("N/A");
        }
        pw.println();
    }
}
 
Example 12
Source File: JobStatus.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Convenience function to identify a job uniquely without pulling all the data that
 * {@link #toString()} returns.
 */
public String toShortString() {
    StringBuilder sb = new StringBuilder();
    sb.append(Integer.toHexString(System.identityHashCode(this)));
    sb.append(" #");
    UserHandle.formatUid(sb, callingUid);
    sb.append("/");
    sb.append(job.getId());
    sb.append(' ');
    sb.append(batteryName);
    return sb.toString();
}
 
Example 13
Source File: JobPackageTracker.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public boolean dumpHistory(PrintWriter pw, String prefix, int filterUid) {
    final int size = mEventIndices.size();
    if (size <= 0) {
        return false;
    }
    pw.println("  Job history:");
    final long now = sElapsedRealtimeClock.millis();
    for (int i=0; i<size; i++) {
        final int index = mEventIndices.indexOf(i);
        final int uid = mEventUids[index];
        if (filterUid != -1 && filterUid != UserHandle.getAppId(uid)) {
            continue;
        }
        final int cmd = mEventCmds[index] & EVENT_CMD_MASK;
        if (cmd == EVENT_NULL) {
            continue;
        }
        final String label;
        switch (cmd) {
            case EVENT_START_JOB:           label = "  START"; break;
            case EVENT_STOP_JOB:            label = "   STOP"; break;
            case EVENT_START_PERIODIC_JOB:  label = "START-P"; break;
            case EVENT_STOP_PERIODIC_JOB:   label = " STOP-P"; break;
            default:                        label = "     ??"; break;
        }
        pw.print(prefix);
        TimeUtils.formatDuration(mEventTimes[index]-now, pw, TimeUtils.HUNDRED_DAY_FIELD_LEN);
        pw.print(" ");
        pw.print(label);
        pw.print(": #");
        UserHandle.formatUid(pw, uid);
        pw.print("/");
        pw.print(mEventJobIds[index]);
        pw.print(" ");
        pw.print(mEventTags[index]);
        if (cmd == EVENT_STOP_JOB || cmd == EVENT_STOP_PERIODIC_JOB) {
            pw.print(" ");
            final String reason = mEventReasons[index];
            if (reason != null) {
                pw.print(mEventReasons[index]);
            } else {
                pw.print(JobParameters.getReasonName((mEventCmds[index] & EVENT_STOP_REASON_MASK)
                        >> EVENT_STOP_REASON_SHIFT));
            }
        }
        pw.println();
    }
    return true;
}
 
Example 14
Source File: DeviceIdleController.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example 15
Source File: SyncOperation.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
String dump(PackageManager pm, boolean shorter, SyncAdapterStateFetcher appStates,
        boolean logSafe) {
    StringBuilder sb = new StringBuilder();
    sb.append("JobId=").append(jobId)
            .append(" ")
            .append(logSafe ? "***" : target.account.name)
            .append("/")
            .append(target.account.type)
            .append(" u")
            .append(target.userId)
            .append(" [")
            .append(target.provider)
            .append("] ");
    sb.append(SyncStorageEngine.SOURCES[syncSource]);
    if (expectedRuntime != 0) {
        sb.append(" ExpectedIn=");
        SyncManager.formatDurationHMS(sb,
                (expectedRuntime - SystemClock.elapsedRealtime()));
    }
    if (extras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false)) {
        sb.append(" EXPEDITED");
    }
    switch (syncExemptionFlag) {
        case ContentResolver.SYNC_EXEMPTION_NONE:
            break;
        case ContentResolver.SYNC_EXEMPTION_PROMOTE_BUCKET:
            sb.append(" STANDBY-EXEMPTED");
            break;
        case ContentResolver.SYNC_EXEMPTION_PROMOTE_BUCKET_WITH_TEMP:
            sb.append(" STANDBY-EXEMPTED(TOP)");
            break;
        default:
            sb.append(" ExemptionFlag=" + syncExemptionFlag);
            break;
    }
    sb.append(" Reason=");
    sb.append(reasonToString(pm, reason));
    if (isPeriodic) {
        sb.append(" (period=");
        SyncManager.formatDurationHMS(sb, periodMillis);
        sb.append(" flex=");
        SyncManager.formatDurationHMS(sb, flexMillis);
        sb.append(")");
    }
    if (retries > 0) {
        sb.append(" Retries=");
        sb.append(retries);
    }
    if (!shorter) {
        sb.append(" Owner={");
        UserHandle.formatUid(sb, owningUid);
        sb.append(" ");
        sb.append(owningPackage);
        if (appStates != null) {
            sb.append(" [");
            sb.append(appStates.getStandbyBucket(
                    UserHandle.getUserId(owningUid), owningPackage));
            sb.append("]");

            if (appStates.isAppActive(owningUid)) {
                sb.append(" [ACTIVE]");
            }
        }
        sb.append("}");
        if (!extras.keySet().isEmpty()) {
            sb.append(" ");
            extrasToStringBuilder(extras, sb);
        }
    }
    return sb.toString();
}
 
Example 16
Source File: JobPackageTracker.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
void dump(PrintWriter pw, String header, String prefix, long now, long nowElapsed,
        int filterUid) {
    final long period = getTotalTime(now);
    pw.print(prefix); pw.print(header); pw.print(" at ");
    pw.print(DateFormat.format("yyyy-MM-dd-HH-mm-ss", mStartClockTime).toString());
    pw.print(" (");
    TimeUtils.formatDuration(mStartElapsedTime, nowElapsed, pw);
    pw.print(") over ");
    TimeUtils.formatDuration(period, pw);
    pw.println(":");
    final int NE = mEntries.size();
    for (int i = 0; i < NE; i++) {
        int uid = mEntries.keyAt(i);
        if (filterUid != -1 && filterUid != UserHandle.getAppId(uid)) {
            continue;
        }
        ArrayMap<String, PackageEntry> uidMap = mEntries.valueAt(i);
        final int NP = uidMap.size();
        for (int j = 0; j < NP; j++) {
            PackageEntry pe = uidMap.valueAt(j);
            pw.print(prefix); pw.print("  ");
            UserHandle.formatUid(pw, uid);
            pw.print(" / "); pw.print(uidMap.keyAt(j));
            pw.println(":");
            pw.print(prefix); pw.print("   ");
            printDuration(pw, period, pe.getPendingTime(now), pe.pendingCount, "pending");
            printDuration(pw, period, pe.getActiveTime(now), pe.activeCount, "active");
            printDuration(pw, period, pe.getActiveTopTime(now), pe.activeTopCount,
                    "active-top");
            if (pe.pendingNesting > 0 || pe.hadPending) {
                pw.print(" (pending)");
            }
            if (pe.activeNesting > 0 || pe.hadActive) {
                pw.print(" (active)");
            }
            if (pe.activeTopNesting > 0 || pe.hadActiveTop) {
                pw.print(" (active-top)");
            }
            pw.println();
            if (pe.stopReasons.size() > 0) {
                pw.print(prefix); pw.print("    ");
                for (int k = 0; k < pe.stopReasons.size(); k++) {
                    if (k > 0) {
                        pw.print(", ");
                    }
                    pw.print(pe.stopReasons.valueAt(k));
                    pw.print("x ");
                    pw.print(JobParameters.getReasonName(pe.stopReasons.keyAt(k)));
                }
                pw.println();
            }
        }
    }
    pw.print(prefix); pw.print("  Max concurrency: ");
    pw.print(mMaxTotalActive); pw.print(" total, ");
    pw.print(mMaxFgActive); pw.println(" foreground");
}
 
Example 17
Source File: UidRecord.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public String toString() {
    StringBuilder sb = new StringBuilder(128);
    sb.append("UidRecord{");
    sb.append(Integer.toHexString(System.identityHashCode(this)));
    sb.append(' ');
    UserHandle.formatUid(sb, uid);
    sb.append(' ');
    sb.append(ProcessList.makeProcStateString(curProcState));
    if (ephemeral) {
        sb.append(" ephemeral");
    }
    if (foregroundServices) {
        sb.append(" fgServices");
    }
    if (curWhitelist) {
        sb.append(" whitelist");
    }
    if (lastBackgroundTime > 0) {
        sb.append(" bg:");
        TimeUtils.formatDuration(SystemClock.elapsedRealtime()-lastBackgroundTime, sb);
    }
    if (idle) {
        sb.append(" idle");
    }
    if (lastReportedChange != 0) {
        sb.append(" change:");
        boolean printed = false;
        if ((lastReportedChange & CHANGE_GONE) != 0) {
            printed = true;
            sb.append("gone");
        }
        if ((lastReportedChange & CHANGE_IDLE) != 0) {
            if (printed) {
                sb.append("|");
            }
            printed = true;
            sb.append("idle");
        }
        if ((lastReportedChange & CHANGE_ACTIVE) != 0) {
            if (printed) {
                sb.append("|");
            }
            printed = true;
            sb.append("active");
        }
        if ((lastReportedChange & CHANGE_CACHED) != 0) {
            if (printed) {
                sb.append("|");
            }
            printed = true;
            sb.append("cached");
        }
        if ((lastReportedChange & CHANGE_UNCACHED) != 0) {
            if (printed) {
                sb.append("|");
            }
            sb.append("uncached");
        }
    }
    sb.append(" procs:");
    sb.append(numProcs);
    sb.append(" seq(");
    sb.append(curProcStateSeq);
    sb.append(",");
    sb.append(lastNetworkUpdatedProcStateSeq);
    sb.append(",");
    sb.append(lastDispatchedProcStateSeq);
    sb.append(")}");
    return sb.toString();
}
 
Example 18
Source File: JobStatus.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    StringBuilder sb = new StringBuilder(128);
    sb.append("JobStatus{");
    sb.append(Integer.toHexString(System.identityHashCode(this)));
    sb.append(" #");
    UserHandle.formatUid(sb, callingUid);
    sb.append("/");
    sb.append(job.getId());
    sb.append(' ');
    sb.append(batteryName);
    sb.append(" u=");
    sb.append(getUserId());
    sb.append(" s=");
    sb.append(getSourceUid());
    if (earliestRunTimeElapsedMillis != NO_EARLIEST_RUNTIME
            || latestRunTimeElapsedMillis != NO_LATEST_RUNTIME) {
        long now = sElapsedRealtimeClock.millis();
        sb.append(" TIME=");
        formatRunTime(sb, earliestRunTimeElapsedMillis, NO_EARLIEST_RUNTIME, now);
        sb.append(":");
        formatRunTime(sb, latestRunTimeElapsedMillis, NO_LATEST_RUNTIME, now);
    }
    if (job.getRequiredNetwork() != null) {
        sb.append(" NET");
    }
    if (job.isRequireCharging()) {
        sb.append(" CHARGING");
    }
    if (job.isRequireBatteryNotLow()) {
        sb.append(" BATNOTLOW");
    }
    if (job.isRequireStorageNotLow()) {
        sb.append(" STORENOTLOW");
    }
    if (job.isRequireDeviceIdle()) {
        sb.append(" IDLE");
    }
    if (job.isPeriodic()) {
        sb.append(" PERIODIC");
    }
    if (job.isPersisted()) {
        sb.append(" PERSISTED");
    }
    if ((satisfiedConstraints&CONSTRAINT_DEVICE_NOT_DOZING) == 0) {
        sb.append(" WAIT:DEV_NOT_DOZING");
    }
    if (job.getTriggerContentUris() != null) {
        sb.append(" URIS=");
        sb.append(Arrays.toString(job.getTriggerContentUris()));
    }
    if (numFailures != 0) {
        sb.append(" failures=");
        sb.append(numFailures);
    }
    if (isReady()) {
        sb.append(" READY");
    }
    sb.append("}");
    return sb.toString();
}
 
Example 19
Source File: JobStatus.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public void printUniqueId(PrintWriter pw) {
    UserHandle.formatUid(pw, callingUid);
    pw.print("/");
    pw.print(job.getId());
}