| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import static java.lang.Long.max; |
| 20 |
|
| 21 |
import android.Manifest; |
| 22 |
import android.annotation.CallbackExecutor; |
| 23 |
import android.annotation.IntDef; |
| 24 |
import android.annotation.IntRange; |
| 25 |
import android.annotation.NonNull; |
| 26 |
import android.annotation.Nullable; |
| 27 |
import android.annotation.RequiresPermission; |
| 28 |
import android.annotation.SystemApi; |
| 29 |
import android.annotation.SystemService; |
| 30 |
import android.annotation.TestApi; |
| 31 |
import android.app.usage.UsageStatsManager; |
| 32 |
import android.compat.Compatibility; |
| 33 |
import android.compat.annotation.ChangeId; |
| 34 |
import android.compat.annotation.EnabledAfter; |
| 35 |
import android.compat.annotation.UnsupportedAppUsage; |
| 36 |
import android.content.AttributionSource; |
| 37 |
import android.content.ComponentName; |
| 38 |
import android.content.ContentResolver; |
| 39 |
import android.content.Context; |
| 40 |
import android.content.pm.ApplicationInfo; |
| 41 |
import android.content.pm.PackageManager; |
| 42 |
import android.content.pm.ParceledListSlice; |
| 43 |
import android.database.DatabaseUtils; |
| 44 |
import android.media.AudioAttributes.AttributeUsage; |
| 45 |
import android.os.Binder; |
| 46 |
import android.os.Build; |
| 47 |
import android.os.Handler; |
| 48 |
import android.os.HandlerExecutor; |
| 49 |
import android.os.HandlerThread; |
| 50 |
import android.os.IBinder; |
| 51 |
import android.os.Looper; |
| 52 |
import android.os.PackageTagsList; |
| 53 |
import android.os.Parcel; |
| 54 |
import android.os.Parcelable; |
| 55 |
import android.os.Process; |
| 56 |
import android.os.RemoteCallback; |
| 57 |
import android.os.RemoteException; |
| 58 |
import android.os.ServiceManager; |
| 59 |
import android.os.SystemClock; |
| 60 |
import android.os.UserManager; |
| 61 |
import android.provider.DeviceConfig; |
| 62 |
import android.util.ArrayMap; |
| 63 |
import android.util.ArraySet; |
| 64 |
import android.util.LongSparseArray; |
| 65 |
import android.util.LongSparseLongArray; |
| 66 |
import android.util.Pools; |
| 67 |
import android.util.SparseArray; |
| 68 |
|
| 69 |
import com.android.internal.annotations.GuardedBy; |
| 70 |
import com.android.internal.annotations.Immutable; |
| 71 |
import com.android.internal.app.IAppOpsActiveCallback; |
| 72 |
import com.android.internal.app.IAppOpsAsyncNotedCallback; |
| 73 |
import com.android.internal.app.IAppOpsCallback; |
| 74 |
import com.android.internal.app.IAppOpsNotedCallback; |
| 75 |
import com.android.internal.app.IAppOpsService; |
| 76 |
import com.android.internal.app.IAppOpsStartedCallback; |
| 77 |
import com.android.internal.app.MessageSamplingConfig; |
| 78 |
import com.android.internal.os.RuntimeInit; |
| 79 |
import com.android.internal.os.ZygoteInit; |
| 80 |
import com.android.internal.util.ArrayUtils; |
| 81 |
import com.android.internal.util.DataClass; |
| 82 |
import com.android.internal.util.FrameworkStatsLog; |
| 83 |
import com.android.internal.util.Parcelling; |
| 84 |
import com.android.internal.util.Preconditions; |
| 85 |
|
| 86 |
import java.lang.annotation.ElementType; |
| 87 |
import java.lang.annotation.Retention; |
| 88 |
import java.lang.annotation.RetentionPolicy; |
| 89 |
import java.lang.annotation.Target; |
| 90 |
import java.lang.reflect.Method; |
| 91 |
import java.util.ArrayList; |
| 92 |
import java.util.Arrays; |
| 93 |
import java.util.BitSet; |
| 94 |
import java.util.Collection; |
| 95 |
import java.util.Collections; |
| 96 |
import java.util.HashMap; |
| 97 |
import java.util.List; |
| 98 |
import java.util.Map; |
| 99 |
import java.util.Objects; |
| 100 |
import java.util.concurrent.Executor; |
| 101 |
import java.util.function.Consumer; |
| 102 |
import java.util.function.Supplier; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
@SystemService(Context.APP_OPS_SERVICE) |
| 178 |
public class AppOpsManager { |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
@ChangeId |
| 188 |
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q) |
| 189 |
public static final long CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE = 148180766L; |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
@TestApi |
| 202 |
@ChangeId |
| 203 |
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.R) |
| 204 |
public static final long SECURITY_EXCEPTION_ON_INVALID_ATTRIBUTION_TAG_CHANGE = 151105954L; |
| 205 |
|
| 206 |
private static final String FULL_LOG = "privacy_attribution_tag_full_log_enabled"; |
| 207 |
|
| 208 |
private static final int MAX_UNFORWARDED_OPS = 10; |
| 209 |
|
| 210 |
private static Boolean sFullLog = null; |
| 211 |
|
| 212 |
final Context mContext; |
| 213 |
|
| 214 |
@UnsupportedAppUsage |
| 215 |
final IAppOpsService mService; |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
@GuardedBy("sLock") |
| 222 |
static IAppOpsService sService; |
| 223 |
|
| 224 |
@GuardedBy("mModeWatchers") |
| 225 |
private final ArrayMap<OnOpChangedListener, IAppOpsCallback> mModeWatchers = |
| 226 |
new ArrayMap<>(); |
| 227 |
|
| 228 |
@GuardedBy("mActiveWatchers") |
| 229 |
private final ArrayMap<OnOpActiveChangedListener, IAppOpsActiveCallback> mActiveWatchers = |
| 230 |
new ArrayMap<>(); |
| 231 |
|
| 232 |
@GuardedBy("mStartedWatchers") |
| 233 |
private final ArrayMap<OnOpStartedListener, IAppOpsStartedCallback> mStartedWatchers = |
| 234 |
new ArrayMap<>(); |
| 235 |
|
| 236 |
@GuardedBy("mNotedWatchers") |
| 237 |
private final ArrayMap<OnOpNotedListener, IAppOpsNotedCallback> mNotedWatchers = |
| 238 |
new ArrayMap<>(); |
| 239 |
|
| 240 |
private static final Object sLock = new Object(); |
| 241 |
|
| 242 |
|
| 243 |
@GuardedBy("sLock") |
| 244 |
private static @Nullable OnOpNotedCallback sOnOpNotedCallback; |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
@GuardedBy("sLock") |
| 255 |
private static ArrayList<AsyncNotedAppOp> sUnforwardedOps = new ArrayList<>(); |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
private static OnOpNotedCallback sMessageCollector = |
| 262 |
new OnOpNotedCallback() { |
| 263 |
@Override |
| 264 |
public void onNoted(@NonNull SyncNotedAppOp op) { |
| 265 |
reportStackTraceIfNeeded(op); |
| 266 |
} |
| 267 |
|
| 268 |
@Override |
| 269 |
public void onAsyncNoted(@NonNull AsyncNotedAppOp asyncOp) { |
| 270 |
|
| 271 |
} |
| 272 |
|
| 273 |
@Override |
| 274 |
public void onSelfNoted(@NonNull SyncNotedAppOp op) { |
| 275 |
reportStackTraceIfNeeded(op); |
| 276 |
} |
| 277 |
|
| 278 |
private void reportStackTraceIfNeeded(@NonNull SyncNotedAppOp op) { |
| 279 |
if (!isCollectingStackTraces()) { |
| 280 |
return; |
| 281 |
} |
| 282 |
MessageSamplingConfig config = sConfig; |
| 283 |
if (leftCircularDistance(strOpToOp(op.getOp()), config.getSampledOpCode(), |
| 284 |
_NUM_OP) <= config.getAcceptableLeftDistance() |
| 285 |
|| config.getExpirationTimeSinceBootMillis() |
| 286 |
< SystemClock.elapsedRealtime()) { |
| 287 |
String stackTrace = getFormattedStackTrace(); |
| 288 |
try { |
| 289 |
String packageName = ActivityThread.currentOpPackageName(); |
| 290 |
sConfig = getService().reportRuntimeAppOpAccessMessageAndGetConfig( |
| 291 |
packageName == null ? "" : packageName, op, stackTrace); |
| 292 |
} catch (RemoteException e) { |
| 293 |
e.rethrowFromSystemServer(); |
| 294 |
} |
| 295 |
} |
| 296 |
} |
| 297 |
}; |
| 298 |
|
| 299 |
static IBinder sClientId; |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
@TestApi |
| 309 |
public static final String KEY_TOP_STATE_SETTLE_TIME = "top_state_settle_time"; |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
@TestApi |
| 319 |
public static final String KEY_FG_SERVICE_STATE_SETTLE_TIME = |
| 320 |
"fg_service_state_settle_time"; |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
@TestApi |
| 331 |
public static final String KEY_BG_STATE_SETTLE_TIME = "bg_state_settle_time"; |
| 332 |
|
| 333 |
|
| 334 |
@Retention(RetentionPolicy.SOURCE) |
| 335 |
@IntDef(flag = true, prefix = { "HISTORICAL_MODE_" }, value = { |
| 336 |
HISTORICAL_MODE_DISABLED, |
| 337 |
HISTORICAL_MODE_ENABLED_ACTIVE, |
| 338 |
HISTORICAL_MODE_ENABLED_PASSIVE |
| 339 |
}) |
| 340 |
public @interface HistoricalMode {} |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
@TestApi |
| 347 |
public static final int HISTORICAL_MODE_DISABLED = 0; |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
@TestApi |
| 355 |
public static final int HISTORICAL_MODE_ENABLED_ACTIVE = 1; |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
@TestApi |
| 365 |
public static final int HISTORICAL_MODE_ENABLED_PASSIVE = 2; |
| 366 |
|
| 367 |
|
| 368 |
@Retention(RetentionPolicy.SOURCE) |
| 369 |
@IntDef(prefix = { "MODE_" }, value = { |
| 370 |
MODE_ALLOWED, |
| 371 |
MODE_IGNORED, |
| 372 |
MODE_ERRORED, |
| 373 |
MODE_DEFAULT, |
| 374 |
MODE_FOREGROUND |
| 375 |
}) |
| 376 |
public @interface Mode {} |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
public static final int MODE_ALLOWED = 0; |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
public static final int MODE_IGNORED = 1; |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
public static final int MODE_ERRORED = 2; |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
public static final int MODE_DEFAULT = 3; |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
public static final int MODE_FOREGROUND = 4; |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
public static final int WATCH_FOREGROUND_CHANGES = 1 << 0; |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
public static final int CALL_BACK_ON_SWITCHED_OP = 1 << 1; |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
public static final boolean NOTE_OP_COLLECTION_ENABLED = false; |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
public static final String[] MODE_NAMES = new String[] { |
| 450 |
"allow", |
| 451 |
"ignore", |
| 452 |
"deny", |
| 453 |
"default", |
| 454 |
"foreground", |
| 455 |
}; |
| 456 |
|
| 457 |
|
| 458 |
@Retention(RetentionPolicy.SOURCE) |
| 459 |
@IntDef(prefix = { "UID_STATE_" }, value = { |
| 460 |
UID_STATE_PERSISTENT, |
| 461 |
UID_STATE_TOP, |
| 462 |
UID_STATE_FOREGROUND_SERVICE_LOCATION, |
| 463 |
UID_STATE_FOREGROUND_SERVICE, |
| 464 |
UID_STATE_FOREGROUND, |
| 465 |
UID_STATE_BACKGROUND, |
| 466 |
UID_STATE_CACHED |
| 467 |
}) |
| 468 |
public @interface UidState {} |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
@SystemApi |
| 476 |
public static final int UID_STATE_PERSISTENT = 100; |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
@SystemApi |
| 484 |
public static final int UID_STATE_TOP = 200; |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
@SystemApi |
| 495 |
@Deprecated |
| 496 |
public static final int UID_STATE_FOREGROUND_SERVICE_LOCATION = 300; |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
@SystemApi |
| 504 |
public static final int UID_STATE_FOREGROUND_SERVICE = 400; |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
@SystemApi |
| 512 |
public static final int UID_STATE_FOREGROUND = 500; |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
public static final int UID_STATE_MAX_LAST_NON_RESTRICTED = UID_STATE_FOREGROUND; |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
@SystemApi |
| 527 |
public static final int UID_STATE_BACKGROUND = 600; |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
@SystemApi |
| 535 |
public static final int UID_STATE_CACHED = 700; |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
public static final int MAX_PRIORITY_UID_STATE = UID_STATE_PERSISTENT; |
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
public static final int MIN_PRIORITY_UID_STATE = UID_STATE_CACHED; |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
public static int resolveFirstUnrestrictedUidState(int op) { |
| 557 |
return UID_STATE_FOREGROUND; |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
public static int resolveLastRestrictedUidState(int op) { |
| 568 |
return UID_STATE_BACKGROUND; |
| 569 |
} |
| 570 |
|
| 571 |
|
| 572 |
public static final int[] UID_STATES = { |
| 573 |
UID_STATE_PERSISTENT, |
| 574 |
UID_STATE_TOP, |
| 575 |
UID_STATE_FOREGROUND_SERVICE_LOCATION, |
| 576 |
UID_STATE_FOREGROUND_SERVICE, |
| 577 |
UID_STATE_FOREGROUND, |
| 578 |
UID_STATE_BACKGROUND, |
| 579 |
UID_STATE_CACHED |
| 580 |
}; |
| 581 |
|
| 582 |
|
| 583 |
public static String getUidStateName(@UidState int uidState) { |
| 584 |
switch (uidState) { |
| 585 |
case UID_STATE_PERSISTENT: |
| 586 |
return "pers"; |
| 587 |
case UID_STATE_TOP: |
| 588 |
return "top"; |
| 589 |
case UID_STATE_FOREGROUND_SERVICE_LOCATION: |
| 590 |
return "fgsvcl"; |
| 591 |
case UID_STATE_FOREGROUND_SERVICE: |
| 592 |
return "fgsvc"; |
| 593 |
case UID_STATE_FOREGROUND: |
| 594 |
return "fg"; |
| 595 |
case UID_STATE_BACKGROUND: |
| 596 |
return "bg"; |
| 597 |
case UID_STATE_CACHED: |
| 598 |
return "cch"; |
| 599 |
default: |
| 600 |
return "unknown"; |
| 601 |
} |
| 602 |
} |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
@SystemApi |
| 612 |
public static final int OP_FLAG_SELF = 0x1; |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
@SystemApi |
| 622 |
public static final int OP_FLAG_TRUSTED_PROXY = 0x2; |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
@SystemApi |
| 632 |
public static final int OP_FLAG_UNTRUSTED_PROXY = 0x4; |
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
@SystemApi |
| 642 |
public static final int OP_FLAG_TRUSTED_PROXIED = 0x8; |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
@SystemApi |
| 652 |
public static final int OP_FLAG_UNTRUSTED_PROXIED = 0x10; |
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
@SystemApi |
| 663 |
public static final int OP_FLAGS_ALL = |
| 664 |
OP_FLAG_SELF |
| 665 |
| OP_FLAG_TRUSTED_PROXY |
| 666 |
| OP_FLAG_UNTRUSTED_PROXY |
| 667 |
| OP_FLAG_TRUSTED_PROXIED |
| 668 |
| OP_FLAG_UNTRUSTED_PROXIED; |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
@SystemApi |
| 678 |
public static final int OP_FLAGS_ALL_TRUSTED = AppOpsManager.OP_FLAG_SELF |
| 679 |
| AppOpsManager.OP_FLAG_UNTRUSTED_PROXY |
| 680 |
| AppOpsManager.OP_FLAG_TRUSTED_PROXIED; |
| 681 |
|
| 682 |
|
| 683 |
@Retention(RetentionPolicy.SOURCE) |
| 684 |
@IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 685 |
OP_FLAG_SELF, |
| 686 |
OP_FLAG_TRUSTED_PROXY, |
| 687 |
OP_FLAG_UNTRUSTED_PROXY, |
| 688 |
OP_FLAG_TRUSTED_PROXIED, |
| 689 |
OP_FLAG_UNTRUSTED_PROXIED |
| 690 |
}) |
| 691 |
public @interface OpFlags {} |
| 692 |
|
| 693 |
|
| 694 |
public static final String getFlagName(@OpFlags int flag) { |
| 695 |
switch (flag) { |
| 696 |
case OP_FLAG_SELF: |
| 697 |
return "s"; |
| 698 |
case OP_FLAG_TRUSTED_PROXY: |
| 699 |
return "tp"; |
| 700 |
case OP_FLAG_UNTRUSTED_PROXY: |
| 701 |
return "up"; |
| 702 |
case OP_FLAG_TRUSTED_PROXIED: |
| 703 |
return "tpd"; |
| 704 |
case OP_FLAG_UNTRUSTED_PROXIED: |
| 705 |
return "upd"; |
| 706 |
default: |
| 707 |
return "unknown"; |
| 708 |
} |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
@TestApi |
| 720 |
public static final int ATTRIBUTION_FLAG_ACCESSOR = 0x1; |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
@TestApi |
| 731 |
public static final int ATTRIBUTION_FLAG_INTERMEDIARY = 0x2; |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
@TestApi |
| 742 |
public static final int ATTRIBUTION_FLAG_RECEIVER = 0x4; |
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
public static final int ATTRIBUTION_FLAG_TRUSTED = 0x8; |
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
@TestApi |
| 756 |
public static final int ATTRIBUTION_FLAGS_NONE = 0x0; |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
@TestApi |
| 763 |
public static final int ATTRIBUTION_CHAIN_ID_NONE = -1; |
| 764 |
|
| 765 |
|
| 766 |
@Retention(RetentionPolicy.SOURCE) |
| 767 |
@IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 768 |
ATTRIBUTION_FLAG_ACCESSOR, |
| 769 |
ATTRIBUTION_FLAG_INTERMEDIARY, |
| 770 |
ATTRIBUTION_FLAG_RECEIVER, |
| 771 |
ATTRIBUTION_FLAG_TRUSTED |
| 772 |
}) |
| 773 |
public @interface AttributionFlags {} |
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
public static final int SAMPLING_STRATEGY_DEFAULT = |
| 781 |
FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__DEFAULT; |
| 782 |
|
| 783 |
|
| 784 |
public static final int SAMPLING_STRATEGY_UNIFORM = |
| 785 |
FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__UNIFORM; |
| 786 |
|
| 787 |
|
| 788 |
public static final int SAMPLING_STRATEGY_RARELY_USED = |
| 789 |
FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__RARELY_USED; |
| 790 |
|
| 791 |
|
| 792 |
public static final int SAMPLING_STRATEGY_BOOT_TIME_SAMPLING = |
| 793 |
FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__BOOT_TIME_SAMPLING; |
| 794 |
|
| 795 |
|
| 796 |
public static final int SAMPLING_STRATEGY_UNIFORM_OPS = |
| 797 |
FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__UNIFORM_OPS; |
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
@Retention(RetentionPolicy.SOURCE) |
| 804 |
@IntDef(prefix = {"SAMPLING_STRATEGY_"}, value = { |
| 805 |
SAMPLING_STRATEGY_DEFAULT, |
| 806 |
SAMPLING_STRATEGY_UNIFORM, |
| 807 |
SAMPLING_STRATEGY_RARELY_USED, |
| 808 |
SAMPLING_STRATEGY_BOOT_TIME_SAMPLING, |
| 809 |
SAMPLING_STRATEGY_UNIFORM_OPS |
| 810 |
}) |
| 811 |
public @interface SamplingStrategy {} |
| 812 |
|
| 813 |
private static final int UID_STATE_OFFSET = 31; |
| 814 |
private static final int FLAGS_MASK = 0xFFFFFFFF; |
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
@Retention(RetentionPolicy.SOURCE) |
| 827 |
@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) |
| 828 |
public @interface DataBucketKey { |
| 829 |
} |
| 830 |
|
| 831 |
|
| 832 |
public static String keyToString(@DataBucketKey long key) { |
| 833 |
final int uidState = extractUidStateFromKey(key); |
| 834 |
final int flags = extractFlagsFromKey(key); |
| 835 |
return "[" + getUidStateName(uidState) + "-" + flagsToString(flags) + "]"; |
| 836 |
} |
| 837 |
|
| 838 |
|
| 839 |
public static @DataBucketKey long makeKey(@UidState int uidState, @OpFlags int flags) { |
| 840 |
return ((long) uidState << UID_STATE_OFFSET) | flags; |
| 841 |
} |
| 842 |
|
| 843 |
|
| 844 |
public static int extractUidStateFromKey(@DataBucketKey long key) { |
| 845 |
return (int) (key >> UID_STATE_OFFSET); |
| 846 |
} |
| 847 |
|
| 848 |
|
| 849 |
public static int extractFlagsFromKey(@DataBucketKey long key) { |
| 850 |
return (int) (key & FLAGS_MASK); |
| 851 |
} |
| 852 |
|
| 853 |
|
| 854 |
public static String flagsToString(@OpFlags int flags) { |
| 855 |
final StringBuilder flagsBuilder = new StringBuilder(); |
| 856 |
while (flags != 0) { |
| 857 |
final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 858 |
flags &= ~flag; |
| 859 |
if (flagsBuilder.length() > 0) { |
| 860 |
flagsBuilder.append('|'); |
| 861 |
} |
| 862 |
flagsBuilder.append(getFlagName(flag)); |
| 863 |
} |
| 864 |
return flagsBuilder.toString(); |
| 865 |
} |
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 877 |
public static final int OP_NONE = AppProtoEnums.APP_OP_NONE; |
| 878 |
|
| 879 |
@UnsupportedAppUsage |
| 880 |
@TestApi |
| 881 |
public static final int OP_COARSE_LOCATION = AppProtoEnums.APP_OP_COARSE_LOCATION; |
| 882 |
|
| 883 |
@UnsupportedAppUsage |
| 884 |
public static final int OP_FINE_LOCATION = AppProtoEnums.APP_OP_FINE_LOCATION; |
| 885 |
|
| 886 |
@UnsupportedAppUsage |
| 887 |
public static final int OP_GPS = AppProtoEnums.APP_OP_GPS; |
| 888 |
|
| 889 |
@UnsupportedAppUsage |
| 890 |
public static final int OP_VIBRATE = AppProtoEnums.APP_OP_VIBRATE; |
| 891 |
|
| 892 |
@UnsupportedAppUsage |
| 893 |
public static final int OP_READ_CONTACTS = AppProtoEnums.APP_OP_READ_CONTACTS; |
| 894 |
|
| 895 |
@UnsupportedAppUsage |
| 896 |
public static final int OP_WRITE_CONTACTS = AppProtoEnums.APP_OP_WRITE_CONTACTS; |
| 897 |
|
| 898 |
@UnsupportedAppUsage |
| 899 |
public static final int OP_READ_CALL_LOG = AppProtoEnums.APP_OP_READ_CALL_LOG; |
| 900 |
|
| 901 |
@UnsupportedAppUsage |
| 902 |
public static final int OP_WRITE_CALL_LOG = AppProtoEnums.APP_OP_WRITE_CALL_LOG; |
| 903 |
|
| 904 |
@UnsupportedAppUsage |
| 905 |
public static final int OP_READ_CALENDAR = AppProtoEnums.APP_OP_READ_CALENDAR; |
| 906 |
|
| 907 |
@UnsupportedAppUsage |
| 908 |
public static final int OP_WRITE_CALENDAR = AppProtoEnums.APP_OP_WRITE_CALENDAR; |
| 909 |
|
| 910 |
@UnsupportedAppUsage |
| 911 |
public static final int OP_WIFI_SCAN = AppProtoEnums.APP_OP_WIFI_SCAN; |
| 912 |
|
| 913 |
@UnsupportedAppUsage |
| 914 |
public static final int OP_POST_NOTIFICATION = AppProtoEnums.APP_OP_POST_NOTIFICATION; |
| 915 |
|
| 916 |
@UnsupportedAppUsage |
| 917 |
public static final int OP_NEIGHBORING_CELLS = AppProtoEnums.APP_OP_NEIGHBORING_CELLS; |
| 918 |
|
| 919 |
@UnsupportedAppUsage |
| 920 |
public static final int OP_CALL_PHONE = AppProtoEnums.APP_OP_CALL_PHONE; |
| 921 |
|
| 922 |
@UnsupportedAppUsage |
| 923 |
public static final int OP_READ_SMS = AppProtoEnums.APP_OP_READ_SMS; |
| 924 |
|
| 925 |
@UnsupportedAppUsage |
| 926 |
public static final int OP_WRITE_SMS = AppProtoEnums.APP_OP_WRITE_SMS; |
| 927 |
|
| 928 |
@UnsupportedAppUsage |
| 929 |
public static final int OP_RECEIVE_SMS = AppProtoEnums.APP_OP_RECEIVE_SMS; |
| 930 |
|
| 931 |
@UnsupportedAppUsage |
| 932 |
public static final int OP_RECEIVE_EMERGECY_SMS = |
| 933 |
AppProtoEnums.APP_OP_RECEIVE_EMERGENCY_SMS; |
| 934 |
|
| 935 |
@UnsupportedAppUsage |
| 936 |
public static final int OP_RECEIVE_MMS = AppProtoEnums.APP_OP_RECEIVE_MMS; |
| 937 |
|
| 938 |
@UnsupportedAppUsage |
| 939 |
public static final int OP_RECEIVE_WAP_PUSH = AppProtoEnums.APP_OP_RECEIVE_WAP_PUSH; |
| 940 |
|
| 941 |
@UnsupportedAppUsage |
| 942 |
public static final int OP_SEND_SMS = AppProtoEnums.APP_OP_SEND_SMS; |
| 943 |
|
| 944 |
public static final int OP_MANAGE_ONGOING_CALLS = AppProtoEnums.APP_OP_MANAGE_ONGOING_CALLS; |
| 945 |
|
| 946 |
@UnsupportedAppUsage |
| 947 |
public static final int OP_READ_ICC_SMS = AppProtoEnums.APP_OP_READ_ICC_SMS; |
| 948 |
|
| 949 |
@UnsupportedAppUsage |
| 950 |
public static final int OP_WRITE_ICC_SMS = AppProtoEnums.APP_OP_WRITE_ICC_SMS; |
| 951 |
|
| 952 |
@UnsupportedAppUsage |
| 953 |
public static final int OP_WRITE_SETTINGS = AppProtoEnums.APP_OP_WRITE_SETTINGS; |
| 954 |
|
| 955 |
@UnsupportedAppUsage |
| 956 |
@TestApi |
| 957 |
public static final int OP_SYSTEM_ALERT_WINDOW = AppProtoEnums.APP_OP_SYSTEM_ALERT_WINDOW; |
| 958 |
|
| 959 |
@UnsupportedAppUsage |
| 960 |
public static final int OP_ACCESS_NOTIFICATIONS = |
| 961 |
AppProtoEnums.APP_OP_ACCESS_NOTIFICATIONS; |
| 962 |
|
| 963 |
@UnsupportedAppUsage |
| 964 |
public static final int OP_CAMERA = AppProtoEnums.APP_OP_CAMERA; |
| 965 |
|
| 966 |
@UnsupportedAppUsage |
| 967 |
@TestApi |
| 968 |
public static final int OP_RECORD_AUDIO = AppProtoEnums.APP_OP_RECORD_AUDIO; |
| 969 |
|
| 970 |
@UnsupportedAppUsage |
| 971 |
public static final int OP_PLAY_AUDIO = AppProtoEnums.APP_OP_PLAY_AUDIO; |
| 972 |
|
| 973 |
@UnsupportedAppUsage |
| 974 |
public static final int OP_READ_CLIPBOARD = AppProtoEnums.APP_OP_READ_CLIPBOARD; |
| 975 |
|
| 976 |
@UnsupportedAppUsage |
| 977 |
public static final int OP_WRITE_CLIPBOARD = AppProtoEnums.APP_OP_WRITE_CLIPBOARD; |
| 978 |
|
| 979 |
@UnsupportedAppUsage |
| 980 |
public static final int OP_TAKE_MEDIA_BUTTONS = AppProtoEnums.APP_OP_TAKE_MEDIA_BUTTONS; |
| 981 |
|
| 982 |
@UnsupportedAppUsage |
| 983 |
public static final int OP_TAKE_AUDIO_FOCUS = AppProtoEnums.APP_OP_TAKE_AUDIO_FOCUS; |
| 984 |
|
| 985 |
@UnsupportedAppUsage |
| 986 |
public static final int OP_AUDIO_MASTER_VOLUME = AppProtoEnums.APP_OP_AUDIO_MASTER_VOLUME; |
| 987 |
|
| 988 |
@UnsupportedAppUsage |
| 989 |
public static final int OP_AUDIO_VOICE_VOLUME = AppProtoEnums.APP_OP_AUDIO_VOICE_VOLUME; |
| 990 |
|
| 991 |
@UnsupportedAppUsage |
| 992 |
public static final int OP_AUDIO_RING_VOLUME = AppProtoEnums.APP_OP_AUDIO_RING_VOLUME; |
| 993 |
|
| 994 |
@UnsupportedAppUsage |
| 995 |
public static final int OP_AUDIO_MEDIA_VOLUME = AppProtoEnums.APP_OP_AUDIO_MEDIA_VOLUME; |
| 996 |
|
| 997 |
@UnsupportedAppUsage |
| 998 |
public static final int OP_AUDIO_ALARM_VOLUME = AppProtoEnums.APP_OP_AUDIO_ALARM_VOLUME; |
| 999 |
|
| 1000 |
@UnsupportedAppUsage |
| 1001 |
public static final int OP_AUDIO_NOTIFICATION_VOLUME = |
| 1002 |
AppProtoEnums.APP_OP_AUDIO_NOTIFICATION_VOLUME; |
| 1003 |
|
| 1004 |
@UnsupportedAppUsage |
| 1005 |
public static final int OP_AUDIO_BLUETOOTH_VOLUME = |
| 1006 |
AppProtoEnums.APP_OP_AUDIO_BLUETOOTH_VOLUME; |
| 1007 |
|
| 1008 |
@UnsupportedAppUsage |
| 1009 |
public static final int OP_WAKE_LOCK = AppProtoEnums.APP_OP_WAKE_LOCK; |
| 1010 |
|
| 1011 |
@UnsupportedAppUsage |
| 1012 |
public static final int OP_MONITOR_LOCATION = |
| 1013 |
AppProtoEnums.APP_OP_MONITOR_LOCATION; |
| 1014 |
|
| 1015 |
@UnsupportedAppUsage |
| 1016 |
public static final int OP_MONITOR_HIGH_POWER_LOCATION = |
| 1017 |
AppProtoEnums.APP_OP_MONITOR_HIGH_POWER_LOCATION; |
| 1018 |
|
| 1019 |
@UnsupportedAppUsage |
| 1020 |
public static final int OP_GET_USAGE_STATS = AppProtoEnums.APP_OP_GET_USAGE_STATS; |
| 1021 |
|
| 1022 |
@UnsupportedAppUsage |
| 1023 |
public static final int OP_MUTE_MICROPHONE = AppProtoEnums.APP_OP_MUTE_MICROPHONE; |
| 1024 |
|
| 1025 |
@UnsupportedAppUsage |
| 1026 |
public static final int OP_TOAST_WINDOW = AppProtoEnums.APP_OP_TOAST_WINDOW; |
| 1027 |
|
| 1028 |
@UnsupportedAppUsage |
| 1029 |
public static final int OP_PROJECT_MEDIA = AppProtoEnums.APP_OP_PROJECT_MEDIA; |
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
@UnsupportedAppUsage |
| 1042 |
public static final int OP_ACTIVATE_VPN = AppProtoEnums.APP_OP_ACTIVATE_VPN; |
| 1043 |
|
| 1044 |
@UnsupportedAppUsage |
| 1045 |
public static final int OP_WRITE_WALLPAPER = AppProtoEnums.APP_OP_WRITE_WALLPAPER; |
| 1046 |
|
| 1047 |
@UnsupportedAppUsage |
| 1048 |
public static final int OP_ASSIST_STRUCTURE = AppProtoEnums.APP_OP_ASSIST_STRUCTURE; |
| 1049 |
|
| 1050 |
@UnsupportedAppUsage |
| 1051 |
public static final int OP_ASSIST_SCREENSHOT = AppProtoEnums.APP_OP_ASSIST_SCREENSHOT; |
| 1052 |
|
| 1053 |
@UnsupportedAppUsage |
| 1054 |
public static final int OP_READ_PHONE_STATE = AppProtoEnums.APP_OP_READ_PHONE_STATE; |
| 1055 |
|
| 1056 |
@UnsupportedAppUsage |
| 1057 |
public static final int OP_ADD_VOICEMAIL = AppProtoEnums.APP_OP_ADD_VOICEMAIL; |
| 1058 |
|
| 1059 |
@UnsupportedAppUsage |
| 1060 |
public static final int OP_USE_SIP = AppProtoEnums.APP_OP_USE_SIP; |
| 1061 |
|
| 1062 |
@UnsupportedAppUsage |
| 1063 |
public static final int OP_PROCESS_OUTGOING_CALLS = |
| 1064 |
AppProtoEnums.APP_OP_PROCESS_OUTGOING_CALLS; |
| 1065 |
|
| 1066 |
@UnsupportedAppUsage |
| 1067 |
public static final int OP_USE_FINGERPRINT = AppProtoEnums.APP_OP_USE_FINGERPRINT; |
| 1068 |
|
| 1069 |
@UnsupportedAppUsage |
| 1070 |
public static final int OP_BODY_SENSORS = AppProtoEnums.APP_OP_BODY_SENSORS; |
| 1071 |
|
| 1072 |
@UnsupportedAppUsage |
| 1073 |
public static final int OP_READ_CELL_BROADCASTS = AppProtoEnums.APP_OP_READ_CELL_BROADCASTS; |
| 1074 |
|
| 1075 |
@UnsupportedAppUsage |
| 1076 |
public static final int OP_MOCK_LOCATION = AppProtoEnums.APP_OP_MOCK_LOCATION; |
| 1077 |
|
| 1078 |
@UnsupportedAppUsage |
| 1079 |
public static final int OP_READ_EXTERNAL_STORAGE = AppProtoEnums.APP_OP_READ_EXTERNAL_STORAGE; |
| 1080 |
|
| 1081 |
@UnsupportedAppUsage |
| 1082 |
public static final int OP_WRITE_EXTERNAL_STORAGE = |
| 1083 |
AppProtoEnums.APP_OP_WRITE_EXTERNAL_STORAGE; |
| 1084 |
|
| 1085 |
@UnsupportedAppUsage |
| 1086 |
public static final int OP_TURN_SCREEN_ON = AppProtoEnums.APP_OP_TURN_SCREEN_ON; |
| 1087 |
|
| 1088 |
@UnsupportedAppUsage |
| 1089 |
public static final int OP_GET_ACCOUNTS = AppProtoEnums.APP_OP_GET_ACCOUNTS; |
| 1090 |
|
| 1091 |
@UnsupportedAppUsage |
| 1092 |
public static final int OP_RUN_IN_BACKGROUND = |
| 1093 |
AppProtoEnums.APP_OP_RUN_IN_BACKGROUND; |
| 1094 |
|
| 1095 |
@UnsupportedAppUsage |
| 1096 |
public static final int OP_AUDIO_ACCESSIBILITY_VOLUME = |
| 1097 |
AppProtoEnums.APP_OP_AUDIO_ACCESSIBILITY_VOLUME; |
| 1098 |
|
| 1099 |
@UnsupportedAppUsage |
| 1100 |
public static final int OP_READ_PHONE_NUMBERS = AppProtoEnums.APP_OP_READ_PHONE_NUMBERS; |
| 1101 |
|
| 1102 |
@UnsupportedAppUsage |
| 1103 |
public static final int OP_REQUEST_INSTALL_PACKAGES = |
| 1104 |
AppProtoEnums.APP_OP_REQUEST_INSTALL_PACKAGES; |
| 1105 |
|
| 1106 |
@UnsupportedAppUsage |
| 1107 |
public static final int OP_PICTURE_IN_PICTURE = AppProtoEnums.APP_OP_PICTURE_IN_PICTURE; |
| 1108 |
|
| 1109 |
@UnsupportedAppUsage |
| 1110 |
public static final int OP_INSTANT_APP_START_FOREGROUND = |
| 1111 |
AppProtoEnums.APP_OP_INSTANT_APP_START_FOREGROUND; |
| 1112 |
|
| 1113 |
@UnsupportedAppUsage |
| 1114 |
public static final int OP_ANSWER_PHONE_CALLS = AppProtoEnums.APP_OP_ANSWER_PHONE_CALLS; |
| 1115 |
|
| 1116 |
@UnsupportedAppUsage |
| 1117 |
public static final int OP_RUN_ANY_IN_BACKGROUND = AppProtoEnums.APP_OP_RUN_ANY_IN_BACKGROUND; |
| 1118 |
|
| 1119 |
@UnsupportedAppUsage |
| 1120 |
public static final int OP_CHANGE_WIFI_STATE = AppProtoEnums.APP_OP_CHANGE_WIFI_STATE; |
| 1121 |
|
| 1122 |
@UnsupportedAppUsage |
| 1123 |
public static final int OP_REQUEST_DELETE_PACKAGES = |
| 1124 |
AppProtoEnums.APP_OP_REQUEST_DELETE_PACKAGES; |
| 1125 |
|
| 1126 |
@UnsupportedAppUsage |
| 1127 |
public static final int OP_BIND_ACCESSIBILITY_SERVICE = |
| 1128 |
AppProtoEnums.APP_OP_BIND_ACCESSIBILITY_SERVICE; |
| 1129 |
|
| 1130 |
@UnsupportedAppUsage |
| 1131 |
public static final int OP_ACCEPT_HANDOVER = AppProtoEnums.APP_OP_ACCEPT_HANDOVER; |
| 1132 |
|
| 1133 |
@UnsupportedAppUsage |
| 1134 |
public static final int OP_MANAGE_IPSEC_TUNNELS = AppProtoEnums.APP_OP_MANAGE_IPSEC_TUNNELS; |
| 1135 |
|
| 1136 |
@UnsupportedAppUsage |
| 1137 |
@TestApi |
| 1138 |
public static final int OP_START_FOREGROUND = AppProtoEnums.APP_OP_START_FOREGROUND; |
| 1139 |
|
| 1140 |
@UnsupportedAppUsage |
| 1141 |
public static final int OP_BLUETOOTH_SCAN = AppProtoEnums.APP_OP_BLUETOOTH_SCAN; |
| 1142 |
|
| 1143 |
public static final int OP_BLUETOOTH_CONNECT = AppProtoEnums.APP_OP_BLUETOOTH_CONNECT; |
| 1144 |
|
| 1145 |
public static final int OP_BLUETOOTH_ADVERTISE = AppProtoEnums.APP_OP_BLUETOOTH_ADVERTISE; |
| 1146 |
|
| 1147 |
public static final int OP_USE_BIOMETRIC = AppProtoEnums.APP_OP_USE_BIOMETRIC; |
| 1148 |
|
| 1149 |
public static final int OP_ACTIVITY_RECOGNITION = AppProtoEnums.APP_OP_ACTIVITY_RECOGNITION; |
| 1150 |
|
| 1151 |
public static final int OP_SMS_FINANCIAL_TRANSACTIONS = |
| 1152 |
AppProtoEnums.APP_OP_SMS_FINANCIAL_TRANSACTIONS; |
| 1153 |
|
| 1154 |
public static final int OP_READ_MEDIA_AUDIO = AppProtoEnums.APP_OP_READ_MEDIA_AUDIO; |
| 1155 |
|
| 1156 |
public static final int OP_WRITE_MEDIA_AUDIO = AppProtoEnums.APP_OP_WRITE_MEDIA_AUDIO; |
| 1157 |
|
| 1158 |
public static final int OP_READ_MEDIA_VIDEO = AppProtoEnums.APP_OP_READ_MEDIA_VIDEO; |
| 1159 |
|
| 1160 |
public static final int OP_WRITE_MEDIA_VIDEO = AppProtoEnums.APP_OP_WRITE_MEDIA_VIDEO; |
| 1161 |
|
| 1162 |
public static final int OP_READ_MEDIA_IMAGES = AppProtoEnums.APP_OP_READ_MEDIA_IMAGES; |
| 1163 |
|
| 1164 |
public static final int OP_WRITE_MEDIA_IMAGES = AppProtoEnums.APP_OP_WRITE_MEDIA_IMAGES; |
| 1165 |
|
| 1166 |
public static final int OP_LEGACY_STORAGE = AppProtoEnums.APP_OP_LEGACY_STORAGE; |
| 1167 |
|
| 1168 |
public static final int OP_ACCESS_ACCESSIBILITY = AppProtoEnums.APP_OP_ACCESS_ACCESSIBILITY; |
| 1169 |
|
| 1170 |
public static final int OP_READ_DEVICE_IDENTIFIERS = |
| 1171 |
AppProtoEnums.APP_OP_READ_DEVICE_IDENTIFIERS; |
| 1172 |
|
| 1173 |
public static final int OP_ACCESS_MEDIA_LOCATION = AppProtoEnums.APP_OP_ACCESS_MEDIA_LOCATION; |
| 1174 |
|
| 1175 |
public static final int OP_QUERY_ALL_PACKAGES = AppProtoEnums.APP_OP_QUERY_ALL_PACKAGES; |
| 1176 |
|
| 1177 |
public static final int OP_MANAGE_EXTERNAL_STORAGE = |
| 1178 |
AppProtoEnums.APP_OP_MANAGE_EXTERNAL_STORAGE; |
| 1179 |
|
| 1180 |
public static final int OP_INTERACT_ACROSS_PROFILES = |
| 1181 |
AppProtoEnums.APP_OP_INTERACT_ACROSS_PROFILES; |
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
public static final int OP_ACTIVATE_PLATFORM_VPN = AppProtoEnums.APP_OP_ACTIVATE_PLATFORM_VPN; |
| 1193 |
|
| 1194 |
public static final int OP_LOADER_USAGE_STATS = AppProtoEnums.APP_OP_LOADER_USAGE_STATS; |
| 1195 |
|
| 1196 |
|
| 1197 |
private static final int OP_DEPRECATED_1 = AppProtoEnums.APP_OP_DEPRECATED_1; |
| 1198 |
|
| 1199 |
|
| 1200 |
public static final int OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED = |
| 1201 |
AppProtoEnums.APP_OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED; |
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
public static final int OP_AUTO_REVOKE_MANAGED_BY_INSTALLER = |
| 1210 |
AppProtoEnums.APP_OP_AUTO_REVOKE_MANAGED_BY_INSTALLER; |
| 1211 |
|
| 1212 |
|
| 1213 |
public static final int OP_NO_ISOLATED_STORAGE = AppProtoEnums.APP_OP_NO_ISOLATED_STORAGE; |
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
public static final int OP_PHONE_CALL_MICROPHONE = AppProtoEnums.APP_OP_PHONE_CALL_MICROPHONE; |
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
public static final int OP_PHONE_CALL_CAMERA = AppProtoEnums.APP_OP_PHONE_CALL_CAMERA; |
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
public static final int OP_RECORD_AUDIO_HOTWORD = AppProtoEnums.APP_OP_RECORD_AUDIO_HOTWORD; |
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
public static final int OP_MANAGE_CREDENTIALS = AppProtoEnums.APP_OP_MANAGE_CREDENTIALS; |
| 1241 |
|
| 1242 |
|
| 1243 |
public static final int OP_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER = |
| 1244 |
AppProtoEnums.APP_OP_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER; |
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
public static final int OP_RECORD_AUDIO_OUTPUT = AppProtoEnums.APP_OP_RECORD_AUDIO_OUTPUT; |
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
public static final int OP_SCHEDULE_EXACT_ALARM = AppProtoEnums.APP_OP_SCHEDULE_EXACT_ALARM; |
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
public static final int OP_FINE_LOCATION_SOURCE = AppProtoEnums.APP_OP_FINE_LOCATION_SOURCE; |
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
public static final int OP_COARSE_LOCATION_SOURCE = AppProtoEnums.APP_OP_COARSE_LOCATION_SOURCE; |
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
public static final int OP_MANAGE_MEDIA = AppProtoEnums.APP_OP_MANAGE_MEDIA; |
| 1291 |
|
| 1292 |
|
| 1293 |
public static final int OP_UWB_RANGING = AppProtoEnums.APP_OP_UWB_RANGING; |
| 1294 |
|
| 1295 |
|
| 1296 |
public static final int OP_NEARBY_WIFI_DEVICES = AppProtoEnums.APP_OP_NEARBY_WIFI_DEVICES; |
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
public static final int OP_ACTIVITY_RECOGNITION_SOURCE = |
| 1306 |
AppProtoEnums.APP_OP_ACTIVITY_RECOGNITION_SOURCE; |
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
public static final int OP_RECORD_INCOMING_PHONE_AUDIO = |
| 1314 |
AppProtoEnums.APP_OP_RECORD_INCOMING_PHONE_AUDIO; |
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
public static final int OP_ESTABLISH_VPN_SERVICE = AppProtoEnums.APP_OP_ESTABLISH_VPN_SERVICE; |
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
public static final int OP_ESTABLISH_VPN_MANAGER = AppProtoEnums.APP_OP_ESTABLISH_VPN_MANAGER; |
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
public static final int OP_ACCESS_RESTRICTED_SETTINGS = |
| 1336 |
AppProtoEnums.APP_OP_ACCESS_RESTRICTED_SETTINGS; |
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
public static final int OP_RECEIVE_AMBIENT_TRIGGER_AUDIO = |
| 1344 |
AppProtoEnums.APP_OP_RECEIVE_AMBIENT_TRIGGER_AUDIO; |
| 1345 |
|
| 1346 |
|
| 1347 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 1348 |
public static final int _NUM_OP = 121; |
| 1349 |
|
| 1350 |
|
| 1351 |
public static final String OPSTR_COARSE_LOCATION = "android:coarse_location"; |
| 1352 |
|
| 1353 |
public static final String OPSTR_FINE_LOCATION = |
| 1354 |
"android:fine_location"; |
| 1355 |
|
| 1356 |
public static final String OPSTR_MONITOR_LOCATION |
| 1357 |
= "android:monitor_location"; |
| 1358 |
|
| 1359 |
public static final String OPSTR_MONITOR_HIGH_POWER_LOCATION |
| 1360 |
= "android:monitor_location_high_power"; |
| 1361 |
|
| 1362 |
public static final String OPSTR_GET_USAGE_STATS |
| 1363 |
= "android:get_usage_stats"; |
| 1364 |
|
| 1365 |
@SystemApi |
| 1366 |
public static final String OPSTR_ACTIVATE_VPN |
| 1367 |
= "android:activate_vpn"; |
| 1368 |
|
| 1369 |
public static final String OPSTR_READ_CONTACTS |
| 1370 |
= "android:read_contacts"; |
| 1371 |
|
| 1372 |
public static final String OPSTR_WRITE_CONTACTS |
| 1373 |
= "android:write_contacts"; |
| 1374 |
|
| 1375 |
public static final String OPSTR_READ_CALL_LOG |
| 1376 |
= "android:read_call_log"; |
| 1377 |
|
| 1378 |
public static final String OPSTR_WRITE_CALL_LOG |
| 1379 |
= "android:write_call_log"; |
| 1380 |
|
| 1381 |
public static final String OPSTR_READ_CALENDAR |
| 1382 |
= "android:read_calendar"; |
| 1383 |
|
| 1384 |
public static final String OPSTR_WRITE_CALENDAR |
| 1385 |
= "android:write_calendar"; |
| 1386 |
|
| 1387 |
public static final String OPSTR_CALL_PHONE |
| 1388 |
= "android:call_phone"; |
| 1389 |
|
| 1390 |
public static final String OPSTR_READ_SMS |
| 1391 |
= "android:read_sms"; |
| 1392 |
|
| 1393 |
public static final String OPSTR_RECEIVE_SMS |
| 1394 |
= "android:receive_sms"; |
| 1395 |
|
| 1396 |
public static final String OPSTR_RECEIVE_MMS |
| 1397 |
= "android:receive_mms"; |
| 1398 |
|
| 1399 |
public static final String OPSTR_RECEIVE_WAP_PUSH |
| 1400 |
= "android:receive_wap_push"; |
| 1401 |
|
| 1402 |
public static final String OPSTR_SEND_SMS |
| 1403 |
= "android:send_sms"; |
| 1404 |
|
| 1405 |
public static final String OPSTR_CAMERA |
| 1406 |
= "android:camera"; |
| 1407 |
|
| 1408 |
public static final String OPSTR_RECORD_AUDIO |
| 1409 |
= "android:record_audio"; |
| 1410 |
|
| 1411 |
public static final String OPSTR_READ_PHONE_STATE |
| 1412 |
= "android:read_phone_state"; |
| 1413 |
|
| 1414 |
public static final String OPSTR_ADD_VOICEMAIL |
| 1415 |
= "android:add_voicemail"; |
| 1416 |
|
| 1417 |
public static final String OPSTR_USE_SIP |
| 1418 |
= "android:use_sip"; |
| 1419 |
|
| 1420 |
public static final String OPSTR_PROCESS_OUTGOING_CALLS |
| 1421 |
= "android:process_outgoing_calls"; |
| 1422 |
|
| 1423 |
public static final String OPSTR_USE_FINGERPRINT |
| 1424 |
= "android:use_fingerprint"; |
| 1425 |
|
| 1426 |
public static final String OPSTR_BODY_SENSORS |
| 1427 |
= "android:body_sensors"; |
| 1428 |
|
| 1429 |
public static final String OPSTR_READ_CELL_BROADCASTS |
| 1430 |
= "android:read_cell_broadcasts"; |
| 1431 |
|
| 1432 |
public static final String OPSTR_MOCK_LOCATION |
| 1433 |
= "android:mock_location"; |
| 1434 |
|
| 1435 |
public static final String OPSTR_READ_EXTERNAL_STORAGE |
| 1436 |
= "android:read_external_storage"; |
| 1437 |
|
| 1438 |
public static final String OPSTR_WRITE_EXTERNAL_STORAGE |
| 1439 |
= "android:write_external_storage"; |
| 1440 |
|
| 1441 |
public static final String OPSTR_SYSTEM_ALERT_WINDOW |
| 1442 |
= "android:system_alert_window"; |
| 1443 |
|
| 1444 |
public static final String OPSTR_WRITE_SETTINGS |
| 1445 |
= "android:write_settings"; |
| 1446 |
|
| 1447 |
@SystemApi |
| 1448 |
public static final String OPSTR_GET_ACCOUNTS |
| 1449 |
= "android:get_accounts"; |
| 1450 |
public static final String OPSTR_READ_PHONE_NUMBERS |
| 1451 |
= "android:read_phone_numbers"; |
| 1452 |
|
| 1453 |
public static final String OPSTR_PICTURE_IN_PICTURE |
| 1454 |
= "android:picture_in_picture"; |
| 1455 |
|
| 1456 |
@SystemApi |
| 1457 |
public static final String OPSTR_INSTANT_APP_START_FOREGROUND |
| 1458 |
= "android:instant_app_start_foreground"; |
| 1459 |
|
| 1460 |
public static final String OPSTR_ANSWER_PHONE_CALLS |
| 1461 |
= "android:answer_phone_calls"; |
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
@SystemApi |
| 1467 |
public static final String OPSTR_ACCEPT_HANDOVER |
| 1468 |
= "android:accept_handover"; |
| 1469 |
|
| 1470 |
@SystemApi |
| 1471 |
public static final String OPSTR_GPS = "android:gps"; |
| 1472 |
|
| 1473 |
@SystemApi |
| 1474 |
public static final String OPSTR_VIBRATE = "android:vibrate"; |
| 1475 |
|
| 1476 |
@SystemApi |
| 1477 |
public static final String OPSTR_WIFI_SCAN = "android:wifi_scan"; |
| 1478 |
|
| 1479 |
@SystemApi |
| 1480 |
public static final String OPSTR_POST_NOTIFICATION = "android:post_notification"; |
| 1481 |
|
| 1482 |
@SystemApi |
| 1483 |
public static final String OPSTR_NEIGHBORING_CELLS = "android:neighboring_cells"; |
| 1484 |
|
| 1485 |
@SystemApi |
| 1486 |
public static final String OPSTR_WRITE_SMS = "android:write_sms"; |
| 1487 |
|
| 1488 |
@SystemApi |
| 1489 |
public static final String OPSTR_RECEIVE_EMERGENCY_BROADCAST = |
| 1490 |
"android:receive_emergency_broadcast"; |
| 1491 |
|
| 1492 |
@SystemApi |
| 1493 |
public static final String OPSTR_READ_ICC_SMS = "android:read_icc_sms"; |
| 1494 |
|
| 1495 |
@SystemApi |
| 1496 |
public static final String OPSTR_WRITE_ICC_SMS = "android:write_icc_sms"; |
| 1497 |
|
| 1498 |
@SystemApi |
| 1499 |
public static final String OPSTR_ACCESS_NOTIFICATIONS = "android:access_notifications"; |
| 1500 |
|
| 1501 |
@SystemApi |
| 1502 |
public static final String OPSTR_PLAY_AUDIO = "android:play_audio"; |
| 1503 |
|
| 1504 |
@SystemApi |
| 1505 |
public static final String OPSTR_READ_CLIPBOARD = "android:read_clipboard"; |
| 1506 |
|
| 1507 |
@SystemApi |
| 1508 |
public static final String OPSTR_WRITE_CLIPBOARD = "android:write_clipboard"; |
| 1509 |
|
| 1510 |
@SystemApi |
| 1511 |
public static final String OPSTR_TAKE_MEDIA_BUTTONS = "android:take_media_buttons"; |
| 1512 |
|
| 1513 |
@SystemApi |
| 1514 |
public static final String OPSTR_TAKE_AUDIO_FOCUS = "android:take_audio_focus"; |
| 1515 |
|
| 1516 |
@SystemApi |
| 1517 |
public static final String OPSTR_AUDIO_MASTER_VOLUME = "android:audio_master_volume"; |
| 1518 |
|
| 1519 |
@SystemApi |
| 1520 |
public static final String OPSTR_AUDIO_VOICE_VOLUME = "android:audio_voice_volume"; |
| 1521 |
|
| 1522 |
@SystemApi |
| 1523 |
public static final String OPSTR_AUDIO_RING_VOLUME = "android:audio_ring_volume"; |
| 1524 |
|
| 1525 |
@SystemApi |
| 1526 |
public static final String OPSTR_AUDIO_MEDIA_VOLUME = "android:audio_media_volume"; |
| 1527 |
|
| 1528 |
@SystemApi |
| 1529 |
public static final String OPSTR_AUDIO_ALARM_VOLUME = "android:audio_alarm_volume"; |
| 1530 |
|
| 1531 |
@SystemApi |
| 1532 |
public static final String OPSTR_AUDIO_NOTIFICATION_VOLUME = |
| 1533 |
"android:audio_notification_volume"; |
| 1534 |
|
| 1535 |
@SystemApi |
| 1536 |
public static final String OPSTR_AUDIO_BLUETOOTH_VOLUME = "android:audio_bluetooth_volume"; |
| 1537 |
|
| 1538 |
@SystemApi |
| 1539 |
public static final String OPSTR_WAKE_LOCK = "android:wake_lock"; |
| 1540 |
|
| 1541 |
@SystemApi |
| 1542 |
public static final String OPSTR_MUTE_MICROPHONE = "android:mute_microphone"; |
| 1543 |
|
| 1544 |
@SystemApi |
| 1545 |
public static final String OPSTR_TOAST_WINDOW = "android:toast_window"; |
| 1546 |
|
| 1547 |
@SystemApi |
| 1548 |
public static final String OPSTR_PROJECT_MEDIA = "android:project_media"; |
| 1549 |
|
| 1550 |
@SystemApi |
| 1551 |
public static final String OPSTR_WRITE_WALLPAPER = "android:write_wallpaper"; |
| 1552 |
|
| 1553 |
@SystemApi |
| 1554 |
public static final String OPSTR_ASSIST_STRUCTURE = "android:assist_structure"; |
| 1555 |
|
| 1556 |
@SystemApi |
| 1557 |
public static final String OPSTR_ASSIST_SCREENSHOT = "android:assist_screenshot"; |
| 1558 |
|
| 1559 |
@SystemApi |
| 1560 |
public static final String OPSTR_TURN_SCREEN_ON = "android:turn_screen_on"; |
| 1561 |
|
| 1562 |
@SystemApi |
| 1563 |
public static final String OPSTR_RUN_IN_BACKGROUND = "android:run_in_background"; |
| 1564 |
|
| 1565 |
@SystemApi |
| 1566 |
public static final String OPSTR_AUDIO_ACCESSIBILITY_VOLUME = |
| 1567 |
"android:audio_accessibility_volume"; |
| 1568 |
|
| 1569 |
@SystemApi |
| 1570 |
public static final String OPSTR_REQUEST_INSTALL_PACKAGES = "android:request_install_packages"; |
| 1571 |
|
| 1572 |
@SystemApi |
| 1573 |
public static final String OPSTR_RUN_ANY_IN_BACKGROUND = "android:run_any_in_background"; |
| 1574 |
|
| 1575 |
@SystemApi |
| 1576 |
public static final String OPSTR_CHANGE_WIFI_STATE = "android:change_wifi_state"; |
| 1577 |
|
| 1578 |
@SystemApi |
| 1579 |
public static final String OPSTR_REQUEST_DELETE_PACKAGES = "android:request_delete_packages"; |
| 1580 |
|
| 1581 |
@SystemApi |
| 1582 |
public static final String OPSTR_BIND_ACCESSIBILITY_SERVICE = |
| 1583 |
"android:bind_accessibility_service"; |
| 1584 |
|
| 1585 |
@SystemApi |
| 1586 |
public static final String OPSTR_MANAGE_IPSEC_TUNNELS = "android:manage_ipsec_tunnels"; |
| 1587 |
|
| 1588 |
@SystemApi |
| 1589 |
public static final String OPSTR_START_FOREGROUND = "android:start_foreground"; |
| 1590 |
|
| 1591 |
public static final String OPSTR_BLUETOOTH_SCAN = "android:bluetooth_scan"; |
| 1592 |
|
| 1593 |
public static final String OPSTR_BLUETOOTH_CONNECT = "android:bluetooth_connect"; |
| 1594 |
|
| 1595 |
public static final String OPSTR_BLUETOOTH_ADVERTISE = "android:bluetooth_advertise"; |
| 1596 |
|
| 1597 |
|
| 1598 |
public static final String OPSTR_USE_BIOMETRIC = "android:use_biometric"; |
| 1599 |
|
| 1600 |
|
| 1601 |
@TestApi |
| 1602 |
public static final String OPSTR_ACTIVITY_RECOGNITION = "android:activity_recognition"; |
| 1603 |
|
| 1604 |
|
| 1605 |
public static final String OPSTR_SMS_FINANCIAL_TRANSACTIONS = |
| 1606 |
"android:sms_financial_transactions"; |
| 1607 |
|
| 1608 |
|
| 1609 |
@SystemApi |
| 1610 |
public static final String OPSTR_READ_MEDIA_AUDIO = "android:read_media_audio"; |
| 1611 |
|
| 1612 |
@SystemApi |
| 1613 |
public static final String OPSTR_WRITE_MEDIA_AUDIO = "android:write_media_audio"; |
| 1614 |
|
| 1615 |
@SystemApi |
| 1616 |
public static final String OPSTR_READ_MEDIA_VIDEO = "android:read_media_video"; |
| 1617 |
|
| 1618 |
@SystemApi |
| 1619 |
public static final String OPSTR_WRITE_MEDIA_VIDEO = "android:write_media_video"; |
| 1620 |
|
| 1621 |
@SystemApi |
| 1622 |
public static final String OPSTR_READ_MEDIA_IMAGES = "android:read_media_images"; |
| 1623 |
|
| 1624 |
@SystemApi |
| 1625 |
public static final String OPSTR_WRITE_MEDIA_IMAGES = "android:write_media_images"; |
| 1626 |
|
| 1627 |
@SystemApi |
| 1628 |
public static final String OPSTR_LEGACY_STORAGE = "android:legacy_storage"; |
| 1629 |
|
| 1630 |
public static final String OPSTR_ACCESS_MEDIA_LOCATION = "android:access_media_location"; |
| 1631 |
|
| 1632 |
|
| 1633 |
@SystemApi |
| 1634 |
public static final String OPSTR_ACCESS_ACCESSIBILITY = "android:access_accessibility"; |
| 1635 |
|
| 1636 |
public static final String OPSTR_READ_DEVICE_IDENTIFIERS = "android:read_device_identifiers"; |
| 1637 |
|
| 1638 |
public static final String OPSTR_QUERY_ALL_PACKAGES = "android:query_all_packages"; |
| 1639 |
|
| 1640 |
@SystemApi |
| 1641 |
public static final String OPSTR_MANAGE_EXTERNAL_STORAGE = |
| 1642 |
"android:manage_external_storage"; |
| 1643 |
|
| 1644 |
|
| 1645 |
@SystemApi |
| 1646 |
public static final String OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED = |
| 1647 |
"android:auto_revoke_permissions_if_unused"; |
| 1648 |
|
| 1649 |
|
| 1650 |
@SystemApi |
| 1651 |
public static final String OPSTR_AUTO_REVOKE_MANAGED_BY_INSTALLER = |
| 1652 |
"android:auto_revoke_managed_by_installer"; |
| 1653 |
|
| 1654 |
|
| 1655 |
@SystemApi |
| 1656 |
public static final String OPSTR_INTERACT_ACROSS_PROFILES = "android:interact_across_profiles"; |
| 1657 |
|
| 1658 |
@SystemApi |
| 1659 |
public static final String OPSTR_ACTIVATE_PLATFORM_VPN = "android:activate_platform_vpn"; |
| 1660 |
|
| 1661 |
@SystemApi |
| 1662 |
public static final String OPSTR_LOADER_USAGE_STATS = "android:loader_usage_stats"; |
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
@SystemApi |
| 1670 |
@TestApi |
| 1671 |
public static final String OPSTR_MANAGE_ONGOING_CALLS = "android:manage_ongoing_calls"; |
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) |
| 1682 |
public static final String OPSTR_NO_ISOLATED_STORAGE = "android:no_isolated_storage"; |
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
@SystemApi |
| 1690 |
public static final String OPSTR_PHONE_CALL_MICROPHONE = "android:phone_call_microphone"; |
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
@SystemApi |
| 1697 |
public static final String OPSTR_PHONE_CALL_CAMERA = "android:phone_call_camera"; |
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
@TestApi |
| 1705 |
public static final String OPSTR_RECORD_AUDIO_HOTWORD = "android:record_audio_hotword"; |
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
public static final String OPSTR_MANAGE_CREDENTIALS = "android:manage_credentials"; |
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
@TestApi |
| 1720 |
public static final String OPSTR_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER = |
| 1721 |
"android:use_icc_auth_with_device_identifier"; |
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
public static final String OPSTR_RECORD_AUDIO_OUTPUT = "android:record_audio_output"; |
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
public static final String OPSTR_SCHEDULE_EXACT_ALARM = "android:schedule_exact_alarm"; |
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
public static final String OPSTR_FINE_LOCATION_SOURCE = "android:fine_location_source"; |
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
public static final String OPSTR_COARSE_LOCATION_SOURCE = "android:coarse_location_source"; |
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
public static final String OPSTR_MANAGE_MEDIA = "android:manage_media"; |
| 1765 |
|
| 1766 |
public static final String OPSTR_UWB_RANGING = "android:uwb_ranging"; |
| 1767 |
|
| 1768 |
public static final String OPSTR_NEARBY_WIFI_DEVICES = "android:nearby_wifi_devices"; |
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
@TestApi |
| 1778 |
public static final String OPSTR_ACTIVITY_RECOGNITION_SOURCE = |
| 1779 |
"android:activity_recognition_source"; |
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
public static final String OPSTR_RECORD_INCOMING_PHONE_AUDIO = |
| 1785 |
"android:record_incoming_phone_audio"; |
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
@SystemApi |
| 1793 |
public static final String OPSTR_ESTABLISH_VPN_SERVICE = "android:establish_vpn_service"; |
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
@SystemApi |
| 1801 |
public static final String OPSTR_ESTABLISH_VPN_MANAGER = "android:establish_vpn_manager"; |
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
public static final String OPSTR_ACCESS_RESTRICTED_SETTINGS = |
| 1809 |
"android:access_restricted_settings"; |
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
public static final String OPSTR_RECEIVE_AMBIENT_TRIGGER_AUDIO = |
| 1817 |
"android:receive_ambient_trigger_audio"; |
| 1818 |
|
| 1819 |
|
| 1820 |
private static final byte SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED = 0; |
| 1821 |
|
| 1822 |
private static final byte SHOULD_NOT_COLLECT_NOTE_OP = 1; |
| 1823 |
|
| 1824 |
private static final byte SHOULD_COLLECT_NOTE_OP = 2; |
| 1825 |
|
| 1826 |
@Retention(RetentionPolicy.SOURCE) |
| 1827 |
@IntDef(flag = true, prefix = { "SHOULD_" }, value = { |
| 1828 |
SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED, |
| 1829 |
SHOULD_NOT_COLLECT_NOTE_OP, |
| 1830 |
SHOULD_COLLECT_NOTE_OP |
| 1831 |
}) |
| 1832 |
private @interface ShouldCollectNoteOp {} |
| 1833 |
|
| 1834 |
private static final int[] RUNTIME_AND_APPOP_PERMISSIONS_OPS = { |
| 1835 |
|
| 1836 |
|
| 1837 |
OP_READ_CONTACTS, |
| 1838 |
OP_WRITE_CONTACTS, |
| 1839 |
OP_GET_ACCOUNTS, |
| 1840 |
|
| 1841 |
OP_READ_CALENDAR, |
| 1842 |
OP_WRITE_CALENDAR, |
| 1843 |
|
| 1844 |
OP_SEND_SMS, |
| 1845 |
OP_RECEIVE_SMS, |
| 1846 |
OP_READ_SMS, |
| 1847 |
OP_RECEIVE_WAP_PUSH, |
| 1848 |
OP_RECEIVE_MMS, |
| 1849 |
OP_READ_CELL_BROADCASTS, |
| 1850 |
|
| 1851 |
OP_READ_EXTERNAL_STORAGE, |
| 1852 |
OP_WRITE_EXTERNAL_STORAGE, |
| 1853 |
OP_ACCESS_MEDIA_LOCATION, |
| 1854 |
|
| 1855 |
OP_COARSE_LOCATION, |
| 1856 |
OP_FINE_LOCATION, |
| 1857 |
|
| 1858 |
OP_READ_PHONE_STATE, |
| 1859 |
OP_READ_PHONE_NUMBERS, |
| 1860 |
OP_CALL_PHONE, |
| 1861 |
OP_READ_CALL_LOG, |
| 1862 |
OP_WRITE_CALL_LOG, |
| 1863 |
OP_ADD_VOICEMAIL, |
| 1864 |
OP_USE_SIP, |
| 1865 |
OP_PROCESS_OUTGOING_CALLS, |
| 1866 |
OP_ANSWER_PHONE_CALLS, |
| 1867 |
OP_ACCEPT_HANDOVER, |
| 1868 |
|
| 1869 |
OP_RECORD_AUDIO, |
| 1870 |
|
| 1871 |
OP_CAMERA, |
| 1872 |
|
| 1873 |
OP_BODY_SENSORS, |
| 1874 |
|
| 1875 |
OP_ACTIVITY_RECOGNITION, |
| 1876 |
|
| 1877 |
OP_READ_MEDIA_AUDIO, |
| 1878 |
OP_WRITE_MEDIA_AUDIO, |
| 1879 |
|
| 1880 |
OP_READ_MEDIA_VIDEO, |
| 1881 |
OP_WRITE_MEDIA_VIDEO, |
| 1882 |
OP_READ_MEDIA_IMAGES, |
| 1883 |
OP_WRITE_MEDIA_IMAGES, |
| 1884 |
|
| 1885 |
OP_BLUETOOTH_SCAN, |
| 1886 |
OP_BLUETOOTH_CONNECT, |
| 1887 |
OP_BLUETOOTH_ADVERTISE, |
| 1888 |
OP_UWB_RANGING, |
| 1889 |
OP_NEARBY_WIFI_DEVICES, |
| 1890 |
|
| 1891 |
OP_POST_NOTIFICATION, |
| 1892 |
|
| 1893 |
|
| 1894 |
OP_ACCESS_NOTIFICATIONS, |
| 1895 |
OP_SYSTEM_ALERT_WINDOW, |
| 1896 |
OP_WRITE_SETTINGS, |
| 1897 |
OP_REQUEST_INSTALL_PACKAGES, |
| 1898 |
OP_START_FOREGROUND, |
| 1899 |
OP_SMS_FINANCIAL_TRANSACTIONS, |
| 1900 |
OP_MANAGE_IPSEC_TUNNELS, |
| 1901 |
OP_INSTANT_APP_START_FOREGROUND, |
| 1902 |
OP_MANAGE_EXTERNAL_STORAGE, |
| 1903 |
OP_INTERACT_ACROSS_PROFILES, |
| 1904 |
OP_LOADER_USAGE_STATS, |
| 1905 |
OP_MANAGE_ONGOING_CALLS, |
| 1906 |
OP_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER, |
| 1907 |
OP_SCHEDULE_EXACT_ALARM, |
| 1908 |
OP_MANAGE_MEDIA, |
| 1909 |
}; |
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
private static int[] sOpToSwitch = new int[] { |
| 1920 |
OP_COARSE_LOCATION, |
| 1921 |
OP_FINE_LOCATION, |
| 1922 |
OP_COARSE_LOCATION, |
| 1923 |
OP_VIBRATE, |
| 1924 |
OP_READ_CONTACTS, |
| 1925 |
OP_WRITE_CONTACTS, |
| 1926 |
OP_READ_CALL_LOG, |
| 1927 |
OP_WRITE_CALL_LOG, |
| 1928 |
OP_READ_CALENDAR, |
| 1929 |
OP_WRITE_CALENDAR, |
| 1930 |
OP_COARSE_LOCATION, |
| 1931 |
OP_POST_NOTIFICATION, |
| 1932 |
OP_COARSE_LOCATION, |
| 1933 |
OP_CALL_PHONE, |
| 1934 |
OP_READ_SMS, |
| 1935 |
OP_WRITE_SMS, |
| 1936 |
OP_RECEIVE_SMS, |
| 1937 |
OP_RECEIVE_SMS, |
| 1938 |
OP_RECEIVE_MMS, |
| 1939 |
OP_RECEIVE_WAP_PUSH, |
| 1940 |
OP_SEND_SMS, |
| 1941 |
OP_READ_SMS, |
| 1942 |
OP_WRITE_SMS, |
| 1943 |
OP_WRITE_SETTINGS, |
| 1944 |
OP_SYSTEM_ALERT_WINDOW, |
| 1945 |
OP_ACCESS_NOTIFICATIONS, |
| 1946 |
OP_CAMERA, |
| 1947 |
OP_RECORD_AUDIO, |
| 1948 |
OP_PLAY_AUDIO, |
| 1949 |
OP_READ_CLIPBOARD, |
| 1950 |
OP_WRITE_CLIPBOARD, |
| 1951 |
OP_TAKE_MEDIA_BUTTONS, |
| 1952 |
OP_TAKE_AUDIO_FOCUS, |
| 1953 |
OP_AUDIO_MASTER_VOLUME, |
| 1954 |
OP_AUDIO_VOICE_VOLUME, |
| 1955 |
OP_AUDIO_RING_VOLUME, |
| 1956 |
OP_AUDIO_MEDIA_VOLUME, |
| 1957 |
OP_AUDIO_ALARM_VOLUME, |
| 1958 |
OP_AUDIO_NOTIFICATION_VOLUME, |
| 1959 |
OP_AUDIO_BLUETOOTH_VOLUME, |
| 1960 |
OP_WAKE_LOCK, |
| 1961 |
OP_COARSE_LOCATION, |
| 1962 |
OP_COARSE_LOCATION, |
| 1963 |
OP_GET_USAGE_STATS, |
| 1964 |
OP_MUTE_MICROPHONE, |
| 1965 |
OP_TOAST_WINDOW, |
| 1966 |
OP_PROJECT_MEDIA, |
| 1967 |
OP_ACTIVATE_VPN, |
| 1968 |
OP_WRITE_WALLPAPER, |
| 1969 |
OP_ASSIST_STRUCTURE, |
| 1970 |
OP_ASSIST_SCREENSHOT, |
| 1971 |
OP_READ_PHONE_STATE, |
| 1972 |
OP_ADD_VOICEMAIL, |
| 1973 |
OP_USE_SIP, |
| 1974 |
OP_PROCESS_OUTGOING_CALLS, |
| 1975 |
OP_USE_FINGERPRINT, |
| 1976 |
OP_BODY_SENSORS, |
| 1977 |
OP_READ_CELL_BROADCASTS, |
| 1978 |
OP_MOCK_LOCATION, |
| 1979 |
OP_READ_EXTERNAL_STORAGE, |
| 1980 |
OP_WRITE_EXTERNAL_STORAGE, |
| 1981 |
OP_TURN_SCREEN_ON, |
| 1982 |
OP_GET_ACCOUNTS, |
| 1983 |
OP_RUN_IN_BACKGROUND, |
| 1984 |
OP_AUDIO_ACCESSIBILITY_VOLUME, |
| 1985 |
OP_READ_PHONE_NUMBERS, |
| 1986 |
OP_REQUEST_INSTALL_PACKAGES, |
| 1987 |
OP_PICTURE_IN_PICTURE, |
| 1988 |
OP_INSTANT_APP_START_FOREGROUND, |
| 1989 |
OP_ANSWER_PHONE_CALLS, |
| 1990 |
OP_RUN_ANY_IN_BACKGROUND, |
| 1991 |
OP_CHANGE_WIFI_STATE, |
| 1992 |
OP_REQUEST_DELETE_PACKAGES, |
| 1993 |
OP_BIND_ACCESSIBILITY_SERVICE, |
| 1994 |
OP_ACCEPT_HANDOVER, |
| 1995 |
OP_MANAGE_IPSEC_TUNNELS, |
| 1996 |
OP_START_FOREGROUND, |
| 1997 |
OP_BLUETOOTH_SCAN, |
| 1998 |
OP_USE_BIOMETRIC, |
| 1999 |
OP_ACTIVITY_RECOGNITION, |
| 2000 |
OP_SMS_FINANCIAL_TRANSACTIONS, |
| 2001 |
OP_READ_MEDIA_AUDIO, |
| 2002 |
OP_WRITE_MEDIA_AUDIO, |
| 2003 |
OP_READ_MEDIA_VIDEO, |
| 2004 |
OP_WRITE_MEDIA_VIDEO, |
| 2005 |
OP_READ_MEDIA_IMAGES, |
| 2006 |
OP_WRITE_MEDIA_IMAGES, |
| 2007 |
OP_LEGACY_STORAGE, |
| 2008 |
OP_ACCESS_ACCESSIBILITY, |
| 2009 |
OP_READ_DEVICE_IDENTIFIERS, |
| 2010 |
OP_ACCESS_MEDIA_LOCATION, |
| 2011 |
OP_QUERY_ALL_PACKAGES, |
| 2012 |
OP_MANAGE_EXTERNAL_STORAGE, |
| 2013 |
OP_INTERACT_ACROSS_PROFILES, |
| 2014 |
OP_ACTIVATE_PLATFORM_VPN, |
| 2015 |
OP_LOADER_USAGE_STATS, |
| 2016 |
OP_DEPRECATED_1, |
| 2017 |
OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED, |
| 2018 |
OP_AUTO_REVOKE_MANAGED_BY_INSTALLER, |
| 2019 |
OP_NO_ISOLATED_STORAGE, |
| 2020 |
OP_PHONE_CALL_MICROPHONE, |
| 2021 |
OP_PHONE_CALL_CAMERA, |
| 2022 |
OP_RECORD_AUDIO_HOTWORD, |
| 2023 |
OP_MANAGE_ONGOING_CALLS, |
| 2024 |
OP_MANAGE_CREDENTIALS, |
| 2025 |
OP_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER, |
| 2026 |
OP_RECORD_AUDIO_OUTPUT, |
| 2027 |
OP_SCHEDULE_EXACT_ALARM, |
| 2028 |
OP_FINE_LOCATION, |
| 2029 |
OP_COARSE_LOCATION, |
| 2030 |
OP_MANAGE_MEDIA, |
| 2031 |
OP_BLUETOOTH_CONNECT, |
| 2032 |
OP_UWB_RANGING, |
| 2033 |
OP_ACTIVITY_RECOGNITION, |
| 2034 |
OP_BLUETOOTH_ADVERTISE, |
| 2035 |
OP_RECORD_INCOMING_PHONE_AUDIO, |
| 2036 |
OP_NEARBY_WIFI_DEVICES, |
| 2037 |
OP_ESTABLISH_VPN_SERVICE, |
| 2038 |
OP_ESTABLISH_VPN_MANAGER, |
| 2039 |
OP_ACCESS_RESTRICTED_SETTINGS, |
| 2040 |
OP_RECEIVE_AMBIENT_TRIGGER_AUDIO, |
| 2041 |
}; |
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
private static String[] sOpToString = new String[]{ |
| 2047 |
OPSTR_COARSE_LOCATION, |
| 2048 |
OPSTR_FINE_LOCATION, |
| 2049 |
OPSTR_GPS, |
| 2050 |
OPSTR_VIBRATE, |
| 2051 |
OPSTR_READ_CONTACTS, |
| 2052 |
OPSTR_WRITE_CONTACTS, |
| 2053 |
OPSTR_READ_CALL_LOG, |
| 2054 |
OPSTR_WRITE_CALL_LOG, |
| 2055 |
OPSTR_READ_CALENDAR, |
| 2056 |
OPSTR_WRITE_CALENDAR, |
| 2057 |
OPSTR_WIFI_SCAN, |
| 2058 |
OPSTR_POST_NOTIFICATION, |
| 2059 |
OPSTR_NEIGHBORING_CELLS, |
| 2060 |
OPSTR_CALL_PHONE, |
| 2061 |
OPSTR_READ_SMS, |
| 2062 |
OPSTR_WRITE_SMS, |
| 2063 |
OPSTR_RECEIVE_SMS, |
| 2064 |
OPSTR_RECEIVE_EMERGENCY_BROADCAST, |
| 2065 |
OPSTR_RECEIVE_MMS, |
| 2066 |
OPSTR_RECEIVE_WAP_PUSH, |
| 2067 |
OPSTR_SEND_SMS, |
| 2068 |
OPSTR_READ_ICC_SMS, |
| 2069 |
OPSTR_WRITE_ICC_SMS, |
| 2070 |
OPSTR_WRITE_SETTINGS, |
| 2071 |
OPSTR_SYSTEM_ALERT_WINDOW, |
| 2072 |
OPSTR_ACCESS_NOTIFICATIONS, |
| 2073 |
OPSTR_CAMERA, |
| 2074 |
OPSTR_RECORD_AUDIO, |
| 2075 |
OPSTR_PLAY_AUDIO, |
| 2076 |
OPSTR_READ_CLIPBOARD, |
| 2077 |
OPSTR_WRITE_CLIPBOARD, |
| 2078 |
OPSTR_TAKE_MEDIA_BUTTONS, |
| 2079 |
OPSTR_TAKE_AUDIO_FOCUS, |
| 2080 |
OPSTR_AUDIO_MASTER_VOLUME, |
| 2081 |
OPSTR_AUDIO_VOICE_VOLUME, |
| 2082 |
OPSTR_AUDIO_RING_VOLUME, |
| 2083 |
OPSTR_AUDIO_MEDIA_VOLUME, |
| 2084 |
OPSTR_AUDIO_ALARM_VOLUME, |
| 2085 |
OPSTR_AUDIO_NOTIFICATION_VOLUME, |
| 2086 |
OPSTR_AUDIO_BLUETOOTH_VOLUME, |
| 2087 |
OPSTR_WAKE_LOCK, |
| 2088 |
OPSTR_MONITOR_LOCATION, |
| 2089 |
OPSTR_MONITOR_HIGH_POWER_LOCATION, |
| 2090 |
OPSTR_GET_USAGE_STATS, |
| 2091 |
OPSTR_MUTE_MICROPHONE, |
| 2092 |
OPSTR_TOAST_WINDOW, |
| 2093 |
OPSTR_PROJECT_MEDIA, |
| 2094 |
OPSTR_ACTIVATE_VPN, |
| 2095 |
OPSTR_WRITE_WALLPAPER, |
| 2096 |
OPSTR_ASSIST_STRUCTURE, |
| 2097 |
OPSTR_ASSIST_SCREENSHOT, |
| 2098 |
OPSTR_READ_PHONE_STATE, |
| 2099 |
OPSTR_ADD_VOICEMAIL, |
| 2100 |
OPSTR_USE_SIP, |
| 2101 |
OPSTR_PROCESS_OUTGOING_CALLS, |
| 2102 |
OPSTR_USE_FINGERPRINT, |
| 2103 |
OPSTR_BODY_SENSORS, |
| 2104 |
OPSTR_READ_CELL_BROADCASTS, |
| 2105 |
OPSTR_MOCK_LOCATION, |
| 2106 |
OPSTR_READ_EXTERNAL_STORAGE, |
| 2107 |
OPSTR_WRITE_EXTERNAL_STORAGE, |
| 2108 |
OPSTR_TURN_SCREEN_ON, |
| 2109 |
OPSTR_GET_ACCOUNTS, |
| 2110 |
OPSTR_RUN_IN_BACKGROUND, |
| 2111 |
OPSTR_AUDIO_ACCESSIBILITY_VOLUME, |
| 2112 |
OPSTR_READ_PHONE_NUMBERS, |
| 2113 |
OPSTR_REQUEST_INSTALL_PACKAGES, |
| 2114 |
OPSTR_PICTURE_IN_PICTURE, |
| 2115 |
OPSTR_INSTANT_APP_START_FOREGROUND, |
| 2116 |
OPSTR_ANSWER_PHONE_CALLS, |
| 2117 |
OPSTR_RUN_ANY_IN_BACKGROUND, |
| 2118 |
OPSTR_CHANGE_WIFI_STATE, |
| 2119 |
OPSTR_REQUEST_DELETE_PACKAGES, |
| 2120 |
OPSTR_BIND_ACCESSIBILITY_SERVICE, |
| 2121 |
OPSTR_ACCEPT_HANDOVER, |
| 2122 |
OPSTR_MANAGE_IPSEC_TUNNELS, |
| 2123 |
OPSTR_START_FOREGROUND, |
| 2124 |
OPSTR_BLUETOOTH_SCAN, |
| 2125 |
OPSTR_USE_BIOMETRIC, |
| 2126 |
OPSTR_ACTIVITY_RECOGNITION, |
| 2127 |
OPSTR_SMS_FINANCIAL_TRANSACTIONS, |
| 2128 |
OPSTR_READ_MEDIA_AUDIO, |
| 2129 |
OPSTR_WRITE_MEDIA_AUDIO, |
| 2130 |
OPSTR_READ_MEDIA_VIDEO, |
| 2131 |
OPSTR_WRITE_MEDIA_VIDEO, |
| 2132 |
OPSTR_READ_MEDIA_IMAGES, |
| 2133 |
OPSTR_WRITE_MEDIA_IMAGES, |
| 2134 |
OPSTR_LEGACY_STORAGE, |
| 2135 |
OPSTR_ACCESS_ACCESSIBILITY, |
| 2136 |
OPSTR_READ_DEVICE_IDENTIFIERS, |
| 2137 |
OPSTR_ACCESS_MEDIA_LOCATION, |
| 2138 |
OPSTR_QUERY_ALL_PACKAGES, |
| 2139 |
OPSTR_MANAGE_EXTERNAL_STORAGE, |
| 2140 |
OPSTR_INTERACT_ACROSS_PROFILES, |
| 2141 |
OPSTR_ACTIVATE_PLATFORM_VPN, |
| 2142 |
OPSTR_LOADER_USAGE_STATS, |
| 2143 |
"", |
| 2144 |
OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED, |
| 2145 |
OPSTR_AUTO_REVOKE_MANAGED_BY_INSTALLER, |
| 2146 |
OPSTR_NO_ISOLATED_STORAGE, |
| 2147 |
OPSTR_PHONE_CALL_MICROPHONE, |
| 2148 |
OPSTR_PHONE_CALL_CAMERA, |
| 2149 |
OPSTR_RECORD_AUDIO_HOTWORD, |
| 2150 |
OPSTR_MANAGE_ONGOING_CALLS, |
| 2151 |
OPSTR_MANAGE_CREDENTIALS, |
| 2152 |
OPSTR_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER, |
| 2153 |
OPSTR_RECORD_AUDIO_OUTPUT, |
| 2154 |
OPSTR_SCHEDULE_EXACT_ALARM, |
| 2155 |
OPSTR_FINE_LOCATION_SOURCE, |
| 2156 |
OPSTR_COARSE_LOCATION_SOURCE, |
| 2157 |
OPSTR_MANAGE_MEDIA, |
| 2158 |
OPSTR_BLUETOOTH_CONNECT, |
| 2159 |
OPSTR_UWB_RANGING, |
| 2160 |
OPSTR_ACTIVITY_RECOGNITION_SOURCE, |
| 2161 |
OPSTR_BLUETOOTH_ADVERTISE, |
| 2162 |
OPSTR_RECORD_INCOMING_PHONE_AUDIO, |
| 2163 |
OPSTR_NEARBY_WIFI_DEVICES, |
| 2164 |
OPSTR_ESTABLISH_VPN_SERVICE, |
| 2165 |
OPSTR_ESTABLISH_VPN_MANAGER, |
| 2166 |
OPSTR_ACCESS_RESTRICTED_SETTINGS, |
| 2167 |
OPSTR_RECEIVE_AMBIENT_TRIGGER_AUDIO, |
| 2168 |
}; |
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
private static String[] sOpNames = new String[] { |
| 2175 |
"COARSE_LOCATION", |
| 2176 |
"FINE_LOCATION", |
| 2177 |
"GPS", |
| 2178 |
"VIBRATE", |
| 2179 |
"READ_CONTACTS", |
| 2180 |
"WRITE_CONTACTS", |
| 2181 |
"READ_CALL_LOG", |
| 2182 |
"WRITE_CALL_LOG", |
| 2183 |
"READ_CALENDAR", |
| 2184 |
"WRITE_CALENDAR", |
| 2185 |
"WIFI_SCAN", |
| 2186 |
"POST_NOTIFICATION", |
| 2187 |
"NEIGHBORING_CELLS", |
| 2188 |
"CALL_PHONE", |
| 2189 |
"READ_SMS", |
| 2190 |
"WRITE_SMS", |
| 2191 |
"RECEIVE_SMS", |
| 2192 |
"RECEIVE_EMERGECY_SMS", |
| 2193 |
"RECEIVE_MMS", |
| 2194 |
"RECEIVE_WAP_PUSH", |
| 2195 |
"SEND_SMS", |
| 2196 |
"READ_ICC_SMS", |
| 2197 |
"WRITE_ICC_SMS", |
| 2198 |
"WRITE_SETTINGS", |
| 2199 |
"SYSTEM_ALERT_WINDOW", |
| 2200 |
"ACCESS_NOTIFICATIONS", |
| 2201 |
"CAMERA", |
| 2202 |
"RECORD_AUDIO", |
| 2203 |
"PLAY_AUDIO", |
| 2204 |
"READ_CLIPBOARD", |
| 2205 |
"WRITE_CLIPBOARD", |
| 2206 |
"TAKE_MEDIA_BUTTONS", |
| 2207 |
"TAKE_AUDIO_FOCUS", |
| 2208 |
"AUDIO_MASTER_VOLUME", |
| 2209 |
"AUDIO_VOICE_VOLUME", |
| 2210 |
"AUDIO_RING_VOLUME", |
| 2211 |
"AUDIO_MEDIA_VOLUME", |
| 2212 |
"AUDIO_ALARM_VOLUME", |
| 2213 |
"AUDIO_NOTIFICATION_VOLUME", |
| 2214 |
"AUDIO_BLUETOOTH_VOLUME", |
| 2215 |
"WAKE_LOCK", |
| 2216 |
"MONITOR_LOCATION", |
| 2217 |
"MONITOR_HIGH_POWER_LOCATION", |
| 2218 |
"GET_USAGE_STATS", |
| 2219 |
"MUTE_MICROPHONE", |
| 2220 |
"TOAST_WINDOW", |
| 2221 |
"PROJECT_MEDIA", |
| 2222 |
"ACTIVATE_VPN", |
| 2223 |
"WRITE_WALLPAPER", |
| 2224 |
"ASSIST_STRUCTURE", |
| 2225 |
"ASSIST_SCREENSHOT", |
| 2226 |
"READ_PHONE_STATE", |
| 2227 |
"ADD_VOICEMAIL", |
| 2228 |
"USE_SIP", |
| 2229 |
"PROCESS_OUTGOING_CALLS", |
| 2230 |
"USE_FINGERPRINT", |
| 2231 |
"BODY_SENSORS", |
| 2232 |
"READ_CELL_BROADCASTS", |
| 2233 |
"MOCK_LOCATION", |
| 2234 |
"READ_EXTERNAL_STORAGE", |
| 2235 |
"WRITE_EXTERNAL_STORAGE", |
| 2236 |
"TURN_ON_SCREEN", |
| 2237 |
"GET_ACCOUNTS", |
| 2238 |
"RUN_IN_BACKGROUND", |
| 2239 |
"AUDIO_ACCESSIBILITY_VOLUME", |
| 2240 |
"READ_PHONE_NUMBERS", |
| 2241 |
"REQUEST_INSTALL_PACKAGES", |
| 2242 |
"PICTURE_IN_PICTURE", |
| 2243 |
"INSTANT_APP_START_FOREGROUND", |
| 2244 |
"ANSWER_PHONE_CALLS", |
| 2245 |
"RUN_ANY_IN_BACKGROUND", |
| 2246 |
"CHANGE_WIFI_STATE", |
| 2247 |
"REQUEST_DELETE_PACKAGES", |
| 2248 |
"BIND_ACCESSIBILITY_SERVICE", |
| 2249 |
"ACCEPT_HANDOVER", |
| 2250 |
"MANAGE_IPSEC_TUNNELS", |
| 2251 |
"START_FOREGROUND", |
| 2252 |
"BLUETOOTH_SCAN", |
| 2253 |
"USE_BIOMETRIC", |
| 2254 |
"ACTIVITY_RECOGNITION", |
| 2255 |
"SMS_FINANCIAL_TRANSACTIONS", |
| 2256 |
"READ_MEDIA_AUDIO", |
| 2257 |
"WRITE_MEDIA_AUDIO", |
| 2258 |
"READ_MEDIA_VIDEO", |
| 2259 |
"WRITE_MEDIA_VIDEO", |
| 2260 |
"READ_MEDIA_IMAGES", |
| 2261 |
"WRITE_MEDIA_IMAGES", |
| 2262 |
"LEGACY_STORAGE", |
| 2263 |
"ACCESS_ACCESSIBILITY", |
| 2264 |
"READ_DEVICE_IDENTIFIERS", |
| 2265 |
"ACCESS_MEDIA_LOCATION", |
| 2266 |
"QUERY_ALL_PACKAGES", |
| 2267 |
"MANAGE_EXTERNAL_STORAGE", |
| 2268 |
"INTERACT_ACROSS_PROFILES", |
| 2269 |
"ACTIVATE_PLATFORM_VPN", |
| 2270 |
"LOADER_USAGE_STATS", |
| 2271 |
"deprecated", |
| 2272 |
"AUTO_REVOKE_PERMISSIONS_IF_UNUSED", |
| 2273 |
"AUTO_REVOKE_MANAGED_BY_INSTALLER", |
| 2274 |
"NO_ISOLATED_STORAGE", |
| 2275 |
"PHONE_CALL_MICROPHONE", |
| 2276 |
"PHONE_CALL_CAMERA", |
| 2277 |
"RECORD_AUDIO_HOTWORD", |
| 2278 |
"MANAGE_ONGOING_CALLS", |
| 2279 |
"MANAGE_CREDENTIALS", |
| 2280 |
"USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER", |
| 2281 |
"RECORD_AUDIO_OUTPUT", |
| 2282 |
"SCHEDULE_EXACT_ALARM", |
| 2283 |
"FINE_LOCATION_SOURCE", |
| 2284 |
"COARSE_LOCATION_SOURCE", |
| 2285 |
"MANAGE_MEDIA", |
| 2286 |
"BLUETOOTH_CONNECT", |
| 2287 |
"UWB_RANGING", |
| 2288 |
"ACTIVITY_RECOGNITION_SOURCE", |
| 2289 |
"BLUETOOTH_ADVERTISE", |
| 2290 |
"RECORD_INCOMING_PHONE_AUDIO", |
| 2291 |
"NEARBY_WIFI_DEVICES", |
| 2292 |
"ESTABLISH_VPN_SERVICE", |
| 2293 |
"ESTABLISH_VPN_MANAGER", |
| 2294 |
"ACCESS_RESTRICTED_SETTINGS", |
| 2295 |
"RECEIVE_SOUNDTRIGGER_AUDIO", |
| 2296 |
}; |
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
@UnsupportedAppUsage |
| 2303 |
private static String[] sOpPerms = new String[] { |
| 2304 |
android.Manifest.permission.ACCESS_COARSE_LOCATION, |
| 2305 |
android.Manifest.permission.ACCESS_FINE_LOCATION, |
| 2306 |
null, |
| 2307 |
android.Manifest.permission.VIBRATE, |
| 2308 |
android.Manifest.permission.READ_CONTACTS, |
| 2309 |
android.Manifest.permission.WRITE_CONTACTS, |
| 2310 |
android.Manifest.permission.READ_CALL_LOG, |
| 2311 |
android.Manifest.permission.WRITE_CALL_LOG, |
| 2312 |
android.Manifest.permission.READ_CALENDAR, |
| 2313 |
android.Manifest.permission.WRITE_CALENDAR, |
| 2314 |
android.Manifest.permission.ACCESS_WIFI_STATE, |
| 2315 |
android.Manifest.permission.POST_NOTIFICATIONS, |
| 2316 |
null, |
| 2317 |
android.Manifest.permission.CALL_PHONE, |
| 2318 |
android.Manifest.permission.READ_SMS, |
| 2319 |
null, |
| 2320 |
android.Manifest.permission.RECEIVE_SMS, |
| 2321 |
android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST, |
| 2322 |
android.Manifest.permission.RECEIVE_MMS, |
| 2323 |
android.Manifest.permission.RECEIVE_WAP_PUSH, |
| 2324 |
android.Manifest.permission.SEND_SMS, |
| 2325 |
android.Manifest.permission.READ_SMS, |
| 2326 |
null, |
| 2327 |
android.Manifest.permission.WRITE_SETTINGS, |
| 2328 |
android.Manifest.permission.SYSTEM_ALERT_WINDOW, |
| 2329 |
android.Manifest.permission.ACCESS_NOTIFICATIONS, |
| 2330 |
android.Manifest.permission.CAMERA, |
| 2331 |
android.Manifest.permission.RECORD_AUDIO, |
| 2332 |
null, |
| 2333 |
null, |
| 2334 |
null, |
| 2335 |
null, |
| 2336 |
null, |
| 2337 |
null, |
| 2338 |
null, |
| 2339 |
null, |
| 2340 |
null, |
| 2341 |
null, |
| 2342 |
null, |
| 2343 |
null, |
| 2344 |
android.Manifest.permission.WAKE_LOCK, |
| 2345 |
null, |
| 2346 |
null, |
| 2347 |
android.Manifest.permission.PACKAGE_USAGE_STATS, |
| 2348 |
null, |
| 2349 |
null, |
| 2350 |
null, |
| 2351 |
null, |
| 2352 |
null, |
| 2353 |
null, |
| 2354 |
null, |
| 2355 |
Manifest.permission.READ_PHONE_STATE, |
| 2356 |
Manifest.permission.ADD_VOICEMAIL, |
| 2357 |
Manifest.permission.USE_SIP, |
| 2358 |
Manifest.permission.PROCESS_OUTGOING_CALLS, |
| 2359 |
Manifest.permission.USE_FINGERPRINT, |
| 2360 |
Manifest.permission.BODY_SENSORS, |
| 2361 |
Manifest.permission.READ_CELL_BROADCASTS, |
| 2362 |
null, |
| 2363 |
Manifest.permission.READ_EXTERNAL_STORAGE, |
| 2364 |
Manifest.permission.WRITE_EXTERNAL_STORAGE, |
| 2365 |
null, |
| 2366 |
Manifest.permission.GET_ACCOUNTS, |
| 2367 |
null, |
| 2368 |
null, |
| 2369 |
Manifest.permission.READ_PHONE_NUMBERS, |
| 2370 |
Manifest.permission.REQUEST_INSTALL_PACKAGES, |
| 2371 |
null, |
| 2372 |
Manifest.permission.INSTANT_APP_FOREGROUND_SERVICE, |
| 2373 |
Manifest.permission.ANSWER_PHONE_CALLS, |
| 2374 |
null, |
| 2375 |
Manifest.permission.CHANGE_WIFI_STATE, |
| 2376 |
Manifest.permission.REQUEST_DELETE_PACKAGES, |
| 2377 |
Manifest.permission.BIND_ACCESSIBILITY_SERVICE, |
| 2378 |
Manifest.permission.ACCEPT_HANDOVER, |
| 2379 |
Manifest.permission.MANAGE_IPSEC_TUNNELS, |
| 2380 |
Manifest.permission.FOREGROUND_SERVICE, |
| 2381 |
Manifest.permission.BLUETOOTH_SCAN, |
| 2382 |
Manifest.permission.USE_BIOMETRIC, |
| 2383 |
Manifest.permission.ACTIVITY_RECOGNITION, |
| 2384 |
Manifest.permission.SMS_FINANCIAL_TRANSACTIONS, |
| 2385 |
Manifest.permission.READ_MEDIA_AUDIO, |
| 2386 |
null, |
| 2387 |
Manifest.permission.READ_MEDIA_VIDEO, |
| 2388 |
null, |
| 2389 |
Manifest.permission.READ_MEDIA_IMAGES, |
| 2390 |
null, |
| 2391 |
null, |
| 2392 |
null, |
| 2393 |
null, |
| 2394 |
Manifest.permission.ACCESS_MEDIA_LOCATION, |
| 2395 |
null, |
| 2396 |
Manifest.permission.MANAGE_EXTERNAL_STORAGE, |
| 2397 |
android.Manifest.permission.INTERACT_ACROSS_PROFILES, |
| 2398 |
null, |
| 2399 |
android.Manifest.permission.LOADER_USAGE_STATS, |
| 2400 |
null, |
| 2401 |
null, |
| 2402 |
null, |
| 2403 |
null, |
| 2404 |
null, |
| 2405 |
null, |
| 2406 |
null, |
| 2407 |
Manifest.permission.MANAGE_ONGOING_CALLS, |
| 2408 |
null, |
| 2409 |
Manifest.permission.USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER, |
| 2410 |
null, |
| 2411 |
Manifest.permission.SCHEDULE_EXACT_ALARM, |
| 2412 |
null, |
| 2413 |
null, |
| 2414 |
Manifest.permission.MANAGE_MEDIA, |
| 2415 |
Manifest.permission.BLUETOOTH_CONNECT, |
| 2416 |
Manifest.permission.UWB_RANGING, |
| 2417 |
null, |
| 2418 |
Manifest.permission.BLUETOOTH_ADVERTISE, |
| 2419 |
null, |
| 2420 |
Manifest.permission.NEARBY_WIFI_DEVICES, |
| 2421 |
null, |
| 2422 |
null, |
| 2423 |
null, |
| 2424 |
null, |
| 2425 |
}; |
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
private static String[] sOpRestrictions = new String[] { |
| 2433 |
UserManager.DISALLOW_SHARE_LOCATION, |
| 2434 |
UserManager.DISALLOW_SHARE_LOCATION, |
| 2435 |
UserManager.DISALLOW_SHARE_LOCATION, |
| 2436 |
null, |
| 2437 |
null, |
| 2438 |
null, |
| 2439 |
UserManager.DISALLOW_OUTGOING_CALLS, |
| 2440 |
UserManager.DISALLOW_OUTGOING_CALLS, |
| 2441 |
null, |
| 2442 |
null, |
| 2443 |
UserManager.DISALLOW_SHARE_LOCATION, |
| 2444 |
null, |
| 2445 |
null, |
| 2446 |
null, |
| 2447 |
UserManager.DISALLOW_SMS, |
| 2448 |
UserManager.DISALLOW_SMS, |
| 2449 |
UserManager.DISALLOW_SMS, |
| 2450 |
null, |
| 2451 |
UserManager.DISALLOW_SMS, |
| 2452 |
null, |
| 2453 |
UserManager.DISALLOW_SMS, |
| 2454 |
UserManager.DISALLOW_SMS, |
| 2455 |
UserManager.DISALLOW_SMS, |
| 2456 |
null, |
| 2457 |
UserManager.DISALLOW_CREATE_WINDOWS, |
| 2458 |
null, |
| 2459 |
UserManager.DISALLOW_CAMERA, |
| 2460 |
UserManager.DISALLOW_RECORD_AUDIO, |
| 2461 |
null, |
| 2462 |
null, |
| 2463 |
null, |
| 2464 |
null, |
| 2465 |
null, |
| 2466 |
UserManager.DISALLOW_ADJUST_VOLUME, |
| 2467 |
UserManager.DISALLOW_ADJUST_VOLUME, |
| 2468 |
UserManager.DISALLOW_ADJUST_VOLUME, |
| 2469 |
UserManager.DISALLOW_ADJUST_VOLUME, |
| 2470 |
UserManager.DISALLOW_ADJUST_VOLUME, |
| 2471 |
UserManager.DISALLOW_ADJUST_VOLUME, |
| 2472 |
UserManager.DISALLOW_ADJUST_VOLUME, |
| 2473 |
null, |
| 2474 |
UserManager.DISALLOW_SHARE_LOCATION, |
| 2475 |
UserManager.DISALLOW_SHARE_LOCATION, |
| 2476 |
null, |
| 2477 |
UserManager.DISALLOW_UNMUTE_MICROPHONE, |
| 2478 |
UserManager.DISALLOW_CREATE_WINDOWS, |
| 2479 |
null, |
| 2480 |
null, |
| 2481 |
UserManager.DISALLOW_WALLPAPER, |
| 2482 |
null, |
| 2483 |
null, |
| 2484 |
null, |
| 2485 |
null, |
| 2486 |
null, |
| 2487 |
null, |
| 2488 |
null, |
| 2489 |
null, |
| 2490 |
null, |
| 2491 |
null, |
| 2492 |
null, |
| 2493 |
null, |
| 2494 |
null, |
| 2495 |
null, |
| 2496 |
null, |
| 2497 |
UserManager.DISALLOW_ADJUST_VOLUME, |
| 2498 |
null, |
| 2499 |
null, |
| 2500 |
null, |
| 2501 |
null, |
| 2502 |
null, |
| 2503 |
null, |
| 2504 |
null, |
| 2505 |
null, |
| 2506 |
null, |
| 2507 |
null, |
| 2508 |
null, |
| 2509 |
null, |
| 2510 |
null, |
| 2511 |
null, |
| 2512 |
null, |
| 2513 |
UserManager.DISALLOW_SMS, |
| 2514 |
null, |
| 2515 |
null, |
| 2516 |
null, |
| 2517 |
null, |
| 2518 |
null, |
| 2519 |
null, |
| 2520 |
null, |
| 2521 |
null, |
| 2522 |
null, |
| 2523 |
null, |
| 2524 |
null, |
| 2525 |
null, |
| 2526 |
null, |
| 2527 |
null, |
| 2528 |
null, |
| 2529 |
null, |
| 2530 |
null, |
| 2531 |
null, |
| 2532 |
null, |
| 2533 |
null, |
| 2534 |
null, |
| 2535 |
null, |
| 2536 |
null, |
| 2537 |
null, |
| 2538 |
null, |
| 2539 |
null, |
| 2540 |
null, |
| 2541 |
null, |
| 2542 |
null, |
| 2543 |
null, |
| 2544 |
null, |
| 2545 |
null, |
| 2546 |
null, |
| 2547 |
null, |
| 2548 |
null, |
| 2549 |
null, |
| 2550 |
null, |
| 2551 |
null, |
| 2552 |
null, |
| 2553 |
null, |
| 2554 |
}; |
| 2555 |
|
| 2556 |
|
| 2557 |
|
| 2558 |
|
| 2559 |
|
| 2560 |
private static RestrictionBypass[] sOpAllowSystemRestrictionBypass = new RestrictionBypass[] { |
| 2561 |
new RestrictionBypass(true, false, false), |
| 2562 |
new RestrictionBypass(true, false, false), |
| 2563 |
null, |
| 2564 |
null, |
| 2565 |
null, |
| 2566 |
null, |
| 2567 |
null, |
| 2568 |
null, |
| 2569 |
null, |
| 2570 |
null, |
| 2571 |
new RestrictionBypass(false, true, false), |
| 2572 |
null, |
| 2573 |
null, |
| 2574 |
null, |
| 2575 |
null, |
| 2576 |
null, |
| 2577 |
null, |
| 2578 |
null, |
| 2579 |
null, |
| 2580 |
null, |
| 2581 |
null, |
| 2582 |
null, |
| 2583 |
null, |
| 2584 |
null, |
| 2585 |
new RestrictionBypass(false, true, false), |
| 2586 |
null, |
| 2587 |
null, |
| 2588 |
new RestrictionBypass(false, false, true), |
| 2589 |
null, |
| 2590 |
null, |
| 2591 |
null, |
| 2592 |
null, |
| 2593 |
null, |
| 2594 |
null, |
| 2595 |
null, |
| 2596 |
null, |
| 2597 |
null, |
| 2598 |
null, |
| 2599 |
null, |
| 2600 |
null, |
| 2601 |
null, |
| 2602 |
null, |
| 2603 |
null, |
| 2604 |
null, |
| 2605 |
null, |
| 2606 |
new RestrictionBypass(false, true, false), |
| 2607 |
null, |
| 2608 |
null, |
| 2609 |
null, |
| 2610 |
null, |
| 2611 |
null, |
| 2612 |
null, |
| 2613 |
null, |
| 2614 |
null, |
| 2615 |
null, |
| 2616 |
null, |
| 2617 |
null, |
| 2618 |
null, |
| 2619 |
null, |
| 2620 |
null, |
| 2621 |
null, |
| 2622 |
null, |
| 2623 |
null, |
| 2624 |
null, |
| 2625 |
null, |
| 2626 |
null, |
| 2627 |
null, |
| 2628 |
null, |
| 2629 |
null, |
| 2630 |
null, |
| 2631 |
null, |
| 2632 |
null, |
| 2633 |
null, |
| 2634 |
null, |
| 2635 |
null, |
| 2636 |
null, |
| 2637 |
null, |
| 2638 |
new RestrictionBypass(false, true, false), |
| 2639 |
null, |
| 2640 |
null, |
| 2641 |
null, |
| 2642 |
null, |
| 2643 |
null, |
| 2644 |
null, |
| 2645 |
null, |
| 2646 |
null, |
| 2647 |
null, |
| 2648 |
null, |
| 2649 |
null, |
| 2650 |
null, |
| 2651 |
null, |
| 2652 |
null, |
| 2653 |
null, |
| 2654 |
null, |
| 2655 |
null, |
| 2656 |
null, |
| 2657 |
null, |
| 2658 |
null, |
| 2659 |
null, |
| 2660 |
null, |
| 2661 |
null, |
| 2662 |
null, |
| 2663 |
null, |
| 2664 |
null, |
| 2665 |
null, |
| 2666 |
null, |
| 2667 |
null, |
| 2668 |
null, |
| 2669 |
null, |
| 2670 |
null, |
| 2671 |
null, |
| 2672 |
null, |
| 2673 |
null, |
| 2674 |
null, |
| 2675 |
null, |
| 2676 |
null, |
| 2677 |
null, |
| 2678 |
null, |
| 2679 |
null, |
| 2680 |
null, |
| 2681 |
null, |
| 2682 |
}; |
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
|
| 2687 |
private static int[] sOpDefaultMode = new int[] { |
| 2688 |
AppOpsManager.MODE_ALLOWED, |
| 2689 |
AppOpsManager.MODE_ALLOWED, |
| 2690 |
AppOpsManager.MODE_ALLOWED, |
| 2691 |
AppOpsManager.MODE_ALLOWED, |
| 2692 |
AppOpsManager.MODE_ALLOWED, |
| 2693 |
AppOpsManager.MODE_ALLOWED, |
| 2694 |
AppOpsManager.MODE_ALLOWED, |
| 2695 |
AppOpsManager.MODE_ALLOWED, |
| 2696 |
AppOpsManager.MODE_ALLOWED, |
| 2697 |
AppOpsManager.MODE_ALLOWED, |
| 2698 |
AppOpsManager.MODE_ALLOWED, |
| 2699 |
AppOpsManager.MODE_ALLOWED, |
| 2700 |
AppOpsManager.MODE_ALLOWED, |
| 2701 |
AppOpsManager.MODE_ALLOWED, |
| 2702 |
AppOpsManager.MODE_ALLOWED, |
| 2703 |
AppOpsManager.MODE_IGNORED, |
| 2704 |
AppOpsManager.MODE_ALLOWED, |
| 2705 |
AppOpsManager.MODE_ALLOWED, |
| 2706 |
AppOpsManager.MODE_ALLOWED, |
| 2707 |
AppOpsManager.MODE_ALLOWED, |
| 2708 |
AppOpsManager.MODE_ALLOWED, |
| 2709 |
AppOpsManager.MODE_ALLOWED, |
| 2710 |
AppOpsManager.MODE_ALLOWED, |
| 2711 |
AppOpsManager.MODE_DEFAULT, |
| 2712 |
getSystemAlertWindowDefault(), |
| 2713 |
AppOpsManager.MODE_ALLOWED, |
| 2714 |
AppOpsManager.MODE_ALLOWED, |
| 2715 |
AppOpsManager.MODE_ALLOWED, |
| 2716 |
AppOpsManager.MODE_ALLOWED, |
| 2717 |
AppOpsManager.MODE_ALLOWED, |
| 2718 |
AppOpsManager.MODE_ALLOWED, |
| 2719 |
AppOpsManager.MODE_ALLOWED, |
| 2720 |
AppOpsManager.MODE_ALLOWED, |
| 2721 |
AppOpsManager.MODE_ALLOWED, |
| 2722 |
AppOpsManager.MODE_ALLOWED, |
| 2723 |
AppOpsManager.MODE_ALLOWED, |
| 2724 |
AppOpsManager.MODE_ALLOWED, |
| 2725 |
AppOpsManager.MODE_ALLOWED, |
| 2726 |
AppOpsManager.MODE_ALLOWED, |
| 2727 |
AppOpsManager.MODE_ALLOWED, |
| 2728 |
AppOpsManager.MODE_ALLOWED, |
| 2729 |
AppOpsManager.MODE_ALLOWED, |
| 2730 |
AppOpsManager.MODE_ALLOWED, |
| 2731 |
AppOpsManager.MODE_DEFAULT, |
| 2732 |
AppOpsManager.MODE_ALLOWED, |
| 2733 |
AppOpsManager.MODE_ALLOWED, |
| 2734 |
AppOpsManager.MODE_IGNORED, |
| 2735 |
AppOpsManager.MODE_IGNORED, |
| 2736 |
AppOpsManager.MODE_ALLOWED, |
| 2737 |
AppOpsManager.MODE_ALLOWED, |
| 2738 |
AppOpsManager.MODE_ALLOWED, |
| 2739 |
AppOpsManager.MODE_ALLOWED, |
| 2740 |
AppOpsManager.MODE_ALLOWED, |
| 2741 |
AppOpsManager.MODE_ALLOWED, |
| 2742 |
AppOpsManager.MODE_ALLOWED, |
| 2743 |
AppOpsManager.MODE_ALLOWED, |
| 2744 |
AppOpsManager.MODE_ALLOWED, |
| 2745 |
AppOpsManager.MODE_ALLOWED, |
| 2746 |
AppOpsManager.MODE_ERRORED, |
| 2747 |
AppOpsManager.MODE_ALLOWED, |
| 2748 |
AppOpsManager.MODE_ALLOWED, |
| 2749 |
AppOpsManager.MODE_ALLOWED, |
| 2750 |
AppOpsManager.MODE_ALLOWED, |
| 2751 |
AppOpsManager.MODE_ALLOWED, |
| 2752 |
AppOpsManager.MODE_ALLOWED, |
| 2753 |
AppOpsManager.MODE_ALLOWED, |
| 2754 |
AppOpsManager.MODE_DEFAULT, |
| 2755 |
AppOpsManager.MODE_ALLOWED, |
| 2756 |
AppOpsManager.MODE_DEFAULT, |
| 2757 |
AppOpsManager.MODE_ALLOWED, |
| 2758 |
AppOpsManager.MODE_ALLOWED, |
| 2759 |
AppOpsManager.MODE_ALLOWED, |
| 2760 |
AppOpsManager.MODE_ALLOWED, |
| 2761 |
AppOpsManager.MODE_ALLOWED, |
| 2762 |
AppOpsManager.MODE_ALLOWED, |
| 2763 |
AppOpsManager.MODE_ERRORED, |
| 2764 |
AppOpsManager.MODE_ALLOWED, |
| 2765 |
AppOpsManager.MODE_ALLOWED, |
| 2766 |
AppOpsManager.MODE_ALLOWED, |
| 2767 |
AppOpsManager.MODE_ALLOWED, |
| 2768 |
AppOpsManager.MODE_DEFAULT, |
| 2769 |
AppOpsManager.MODE_ALLOWED, |
| 2770 |
AppOpsManager.MODE_ERRORED, |
| 2771 |
AppOpsManager.MODE_ALLOWED, |
| 2772 |
AppOpsManager.MODE_ERRORED, |
| 2773 |
AppOpsManager.MODE_ALLOWED, |
| 2774 |
AppOpsManager.MODE_ERRORED, |
| 2775 |
AppOpsManager.MODE_DEFAULT, |
| 2776 |
AppOpsManager.MODE_ALLOWED, |
| 2777 |
AppOpsManager.MODE_ERRORED, |
| 2778 |
AppOpsManager.MODE_ALLOWED, |
| 2779 |
AppOpsManager.MODE_DEFAULT, |
| 2780 |
AppOpsManager.MODE_DEFAULT, |
| 2781 |
AppOpsManager.MODE_DEFAULT, |
| 2782 |
AppOpsManager.MODE_IGNORED, |
| 2783 |
AppOpsManager.MODE_DEFAULT, |
| 2784 |
AppOpsManager.MODE_IGNORED, |
| 2785 |
AppOpsManager.MODE_DEFAULT, |
| 2786 |
AppOpsManager.MODE_ALLOWED, |
| 2787 |
AppOpsManager.MODE_ERRORED, |
| 2788 |
AppOpsManager.MODE_ALLOWED, |
| 2789 |
AppOpsManager.MODE_ALLOWED, |
| 2790 |
AppOpsManager.MODE_ALLOWED, |
| 2791 |
AppOpsManager.MODE_DEFAULT, |
| 2792 |
AppOpsManager.MODE_DEFAULT, |
| 2793 |
AppOpsManager.MODE_DEFAULT, |
| 2794 |
AppOpsManager.MODE_ALLOWED, |
| 2795 |
AppOpsManager.MODE_DEFAULT, |
| 2796 |
AppOpsManager.MODE_ALLOWED, |
| 2797 |
AppOpsManager.MODE_ALLOWED, |
| 2798 |
AppOpsManager.MODE_DEFAULT, |
| 2799 |
AppOpsManager.MODE_ALLOWED, |
| 2800 |
AppOpsManager.MODE_ALLOWED, |
| 2801 |
AppOpsManager.MODE_ALLOWED, |
| 2802 |
AppOpsManager.MODE_ALLOWED, |
| 2803 |
AppOpsManager.MODE_ALLOWED, |
| 2804 |
AppOpsManager.MODE_ALLOWED, |
| 2805 |
AppOpsManager.MODE_ALLOWED, |
| 2806 |
AppOpsManager.MODE_ALLOWED, |
| 2807 |
AppOpsManager.MODE_ALLOWED, |
| 2808 |
AppOpsManager.MODE_ALLOWED, |
| 2809 |
}; |
| 2810 |
|
| 2811 |
|
| 2812 |
|
| 2813 |
|
| 2814 |
|
| 2815 |
|
| 2816 |
|
| 2817 |
|
| 2818 |
private static boolean[] sOpDisableReset = new boolean[] { |
| 2819 |
false, |
| 2820 |
false, |
| 2821 |
false, |
| 2822 |
false, |
| 2823 |
false, |
| 2824 |
false, |
| 2825 |
false, |
| 2826 |
false, |
| 2827 |
false, |
| 2828 |
false, |
| 2829 |
false, |
| 2830 |
false, |
| 2831 |
false, |
| 2832 |
false, |
| 2833 |
true, |
| 2834 |
true, |
| 2835 |
true, |
| 2836 |
false, |
| 2837 |
false, |
| 2838 |
true, |
| 2839 |
true, |
| 2840 |
false, |
| 2841 |
false, |
| 2842 |
false, |
| 2843 |
false, |
| 2844 |
false, |
| 2845 |
false, |
| 2846 |
false, |
| 2847 |
false, |
| 2848 |
false, |
| 2849 |
false, |
| 2850 |
false, |
| 2851 |
false, |
| 2852 |
false, |
| 2853 |
false, |
| 2854 |
false, |
| 2855 |
false, |
| 2856 |
false, |
| 2857 |
false, |
| 2858 |
false, |
| 2859 |
false, |
| 2860 |
false, |
| 2861 |
false, |
| 2862 |
false, |
| 2863 |
false, |
| 2864 |
false, |
| 2865 |
false, |
| 2866 |
false, |
| 2867 |
false, |
| 2868 |
false, |
| 2869 |
false, |
| 2870 |
false, |
| 2871 |
false, |
| 2872 |
false, |
| 2873 |
false, |
| 2874 |
false, |
| 2875 |
false, |
| 2876 |
true, |
| 2877 |
false, |
| 2878 |
false, |
| 2879 |
false, |
| 2880 |
false, |
| 2881 |
false, |
| 2882 |
false, |
| 2883 |
false, |
| 2884 |
false, |
| 2885 |
false, |
| 2886 |
false, |
| 2887 |
false, |
| 2888 |
false, |
| 2889 |
false, |
| 2890 |
false, |
| 2891 |
false, |
| 2892 |
false, |
| 2893 |
false, |
| 2894 |
false, |
| 2895 |
false, |
| 2896 |
false, |
| 2897 |
false, |
| 2898 |
false, |
| 2899 |
false, |
| 2900 |
false, |
| 2901 |
false, |
| 2902 |
false, |
| 2903 |
true, |
| 2904 |
false, |
| 2905 |
true, |
| 2906 |
true, |
| 2907 |
false, |
| 2908 |
false, |
| 2909 |
false, |
| 2910 |
false, |
| 2911 |
false, |
| 2912 |
false, |
| 2913 |
false, |
| 2914 |
false, |
| 2915 |
false, |
| 2916 |
false, |
| 2917 |
false, |
| 2918 |
true, |
| 2919 |
false, |
| 2920 |
false, |
| 2921 |
false, |
| 2922 |
true, |
| 2923 |
false, |
| 2924 |
true, |
| 2925 |
false, |
| 2926 |
false, |
| 2927 |
false, |
| 2928 |
false, |
| 2929 |
false, |
| 2930 |
false, |
| 2931 |
false, |
| 2932 |
false, |
| 2933 |
false, |
| 2934 |
false, |
| 2935 |
false, |
| 2936 |
false, |
| 2937 |
false, |
| 2938 |
true, |
| 2939 |
false, |
| 2940 |
}; |
| 2941 |
|
| 2942 |
|
| 2943 |
|
| 2944 |
|
| 2945 |
|
| 2946 |
private static boolean[] sOpRestrictRead = new boolean[] { |
| 2947 |
false, |
| 2948 |
false, |
| 2949 |
false, |
| 2950 |
false, |
| 2951 |
false, |
| 2952 |
false, |
| 2953 |
false, |
| 2954 |
false, |
| 2955 |
false, |
| 2956 |
false, |
| 2957 |
false, |
| 2958 |
false, |
| 2959 |
false, |
| 2960 |
false, |
| 2961 |
false, |
| 2962 |
false, |
| 2963 |
false, |
| 2964 |
false, |
| 2965 |
false, |
| 2966 |
false, |
| 2967 |
false, |
| 2968 |
false, |
| 2969 |
false, |
| 2970 |
false, |
| 2971 |
false, |
| 2972 |
false, |
| 2973 |
false, |
| 2974 |
false, |
| 2975 |
false, |
| 2976 |
false, |
| 2977 |
false, |
| 2978 |
false, |
| 2979 |
false, |
| 2980 |
false, |
| 2981 |
false, |
| 2982 |
false, |
| 2983 |
false, |
| 2984 |
false, |
| 2985 |
false, |
| 2986 |
false, |
| 2987 |
false, |
| 2988 |
false, |
| 2989 |
false, |
| 2990 |
false, |
| 2991 |
false, |
| 2992 |
false, |
| 2993 |
false, |
| 2994 |
false, |
| 2995 |
false, |
| 2996 |
false, |
| 2997 |
false, |
| 2998 |
false, |
| 2999 |
false, |
| 3000 |
false, |
| 3001 |
false, |
| 3002 |
false, |
| 3003 |
false, |
| 3004 |
false, |
| 3005 |
false, |
| 3006 |
false, |
| 3007 |
false, |
| 3008 |
false, |
| 3009 |
false, |
| 3010 |
false, |
| 3011 |
false, |
| 3012 |
false, |
| 3013 |
false, |
| 3014 |
false, |
| 3015 |
false, |
| 3016 |
false, |
| 3017 |
false, |
| 3018 |
false, |
| 3019 |
false, |
| 3020 |
false, |
| 3021 |
false, |
| 3022 |
false, |
| 3023 |
false, |
| 3024 |
false, |
| 3025 |
false, |
| 3026 |
false, |
| 3027 |
false, |
| 3028 |
false, |
| 3029 |
false, |
| 3030 |
false, |
| 3031 |
false, |
| 3032 |
false, |
| 3033 |
false, |
| 3034 |
false, |
| 3035 |
false, |
| 3036 |
false, |
| 3037 |
false, |
| 3038 |
false, |
| 3039 |
false, |
| 3040 |
false, |
| 3041 |
false, |
| 3042 |
false, |
| 3043 |
false, |
| 3044 |
false, |
| 3045 |
false, |
| 3046 |
false, |
| 3047 |
false, |
| 3048 |
false, |
| 3049 |
false, |
| 3050 |
false, |
| 3051 |
false, |
| 3052 |
false, |
| 3053 |
false, |
| 3054 |
false, |
| 3055 |
false, |
| 3056 |
false, |
| 3057 |
false, |
| 3058 |
false, |
| 3059 |
false, |
| 3060 |
false, |
| 3061 |
false, |
| 3062 |
false, |
| 3063 |
false, |
| 3064 |
false, |
| 3065 |
false, |
| 3066 |
true, |
| 3067 |
false, |
| 3068 |
}; |
| 3069 |
|
| 3070 |
|
| 3071 |
|
| 3072 |
|
| 3073 |
private static HashMap<String, Integer> sOpStrToOp = new HashMap<>(); |
| 3074 |
|
| 3075 |
|
| 3076 |
|
| 3077 |
|
| 3078 |
private static HashMap<String, Integer> sPermToOp = new HashMap<>(); |
| 3079 |
|
| 3080 |
|
| 3081 |
|
| 3082 |
|
| 3083 |
|
| 3084 |
|
| 3085 |
|
| 3086 |
|
| 3087 |
private static final ThreadLocal<Integer> sBinderThreadCallingUid = new ThreadLocal<>(); |
| 3088 |
|
| 3089 |
|
| 3090 |
|
| 3091 |
|
| 3092 |
|
| 3093 |
|
| 3094 |
|
| 3095 |
|
| 3096 |
private static final ThreadLocal<ArrayMap<String, long[]>> sAppOpsNotedInThisBinderTransaction = |
| 3097 |
new ThreadLocal<>(); |
| 3098 |
|
| 3099 |
|
| 3100 |
private static final @ShouldCollectNoteOp byte[] sAppOpsToNote = new byte[_NUM_OP]; |
| 3101 |
|
| 3102 |
static { |
| 3103 |
if (sOpToSwitch.length != _NUM_OP) { |
| 3104 |
throw new IllegalStateException("sOpToSwitch length " + sOpToSwitch.length |
| 3105 |
+ " should be " + _NUM_OP); |
| 3106 |
} |
| 3107 |
if (sOpToString.length != _NUM_OP) { |
| 3108 |
throw new IllegalStateException("sOpToString length " + sOpToString.length |
| 3109 |
+ " should be " + _NUM_OP); |
| 3110 |
} |
| 3111 |
if (sOpNames.length != _NUM_OP) { |
| 3112 |
throw new IllegalStateException("sOpNames length " + sOpNames.length |
| 3113 |
+ " should be " + _NUM_OP); |
| 3114 |
} |
| 3115 |
if (sOpPerms.length != _NUM_OP) { |
| 3116 |
throw new IllegalStateException("sOpPerms length " + sOpPerms.length |
| 3117 |
+ " should be " + _NUM_OP); |
| 3118 |
} |
| 3119 |
if (sOpDefaultMode.length != _NUM_OP) { |
| 3120 |
throw new IllegalStateException("sOpDefaultMode length " + sOpDefaultMode.length |
| 3121 |
+ " should be " + _NUM_OP); |
| 3122 |
} |
| 3123 |
if (sOpDisableReset.length != _NUM_OP) { |
| 3124 |
throw new IllegalStateException("sOpDisableReset length " + sOpDisableReset.length |
| 3125 |
+ " should be " + _NUM_OP); |
| 3126 |
} |
| 3127 |
if (sOpRestrictions.length != _NUM_OP) { |
| 3128 |
throw new IllegalStateException("sOpRestrictions length " + sOpRestrictions.length |
| 3129 |
+ " should be " + _NUM_OP); |
| 3130 |
} |
| 3131 |
if (sOpAllowSystemRestrictionBypass.length != _NUM_OP) { |
| 3132 |
throw new IllegalStateException("sOpAllowSYstemRestrictionsBypass length " |
| 3133 |
+ sOpRestrictions.length + " should be " + _NUM_OP); |
| 3134 |
} |
| 3135 |
for (int i=0; i<_NUM_OP; i++) { |
| 3136 |
if (sOpToString[i] != null) { |
| 3137 |
sOpStrToOp.put(sOpToString[i], i); |
| 3138 |
} |
| 3139 |
} |
| 3140 |
for (int op : RUNTIME_AND_APPOP_PERMISSIONS_OPS) { |
| 3141 |
if (sOpPerms[op] != null) { |
| 3142 |
sPermToOp.put(sOpPerms[op], op); |
| 3143 |
} |
| 3144 |
} |
| 3145 |
|
| 3146 |
if ((_NUM_OP + Long.SIZE - 1) / Long.SIZE != 2) { |
| 3147 |
|
| 3148 |
|
| 3149 |
throw new IllegalStateException("notedAppOps collection code assumes < 128 appops"); |
| 3150 |
} |
| 3151 |
} |
| 3152 |
|
| 3153 |
|
| 3154 |
private static MessageSamplingConfig sConfig = |
| 3155 |
new MessageSamplingConfig(OP_NONE, 0, 0); |
| 3156 |
|
| 3157 |
|
| 3158 |
public static final String KEY_HISTORICAL_OPS = "historical_ops"; |
| 3159 |
|
| 3160 |
|
| 3161 |
private static final String DEBUG_LOGGING_ENABLE_PROP = "appops.logging_enabled"; |
| 3162 |
private static final String DEBUG_LOGGING_PACKAGES_PROP = "appops.logging_packages"; |
| 3163 |
private static final String DEBUG_LOGGING_OPS_PROP = "appops.logging_ops"; |
| 3164 |
private static final String DEBUG_LOGGING_TAG = "AppOpsManager"; |
| 3165 |
|
| 3166 |
|
| 3167 |
|
| 3168 |
|
| 3169 |
|
| 3170 |
@UnsupportedAppUsage |
| 3171 |
public static int opToSwitch(int op) { |
| 3172 |
return sOpToSwitch[op]; |
| 3173 |
} |
| 3174 |
|
| 3175 |
|
| 3176 |
|
| 3177 |
|
| 3178 |
|
| 3179 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 3180 |
public static String opToName(int op) { |
| 3181 |
if (op == OP_NONE) return "NONE"; |
| 3182 |
return op < sOpNames.length ? sOpNames[op] : ("Unknown(" + op + ")"); |
| 3183 |
} |
| 3184 |
|
| 3185 |
|
| 3186 |
|
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
public static @NonNull String opToPublicName(int op) { |
| 3191 |
return sOpToString[op]; |
| 3192 |
} |
| 3193 |
|
| 3194 |
|
| 3195 |
|
| 3196 |
|
| 3197 |
public static int strDebugOpToOp(String op) { |
| 3198 |
for (int i=0; i<sOpNames.length; i++) { |
| 3199 |
if (sOpNames[i].equals(op)) { |
| 3200 |
return i; |
| 3201 |
} |
| 3202 |
} |
| 3203 |
throw new IllegalArgumentException("Unknown operation string: " + op); |
| 3204 |
} |
| 3205 |
|
| 3206 |
|
| 3207 |
|
| 3208 |
|
| 3209 |
|
| 3210 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 3211 |
@TestApi |
| 3212 |
public static String opToPermission(int op) { |
| 3213 |
return sOpPerms[op]; |
| 3214 |
} |
| 3215 |
|
| 3216 |
|
| 3217 |
|
| 3218 |
|
| 3219 |
|
| 3220 |
|
| 3221 |
|
| 3222 |
|
| 3223 |
@Nullable |
| 3224 |
@SystemApi |
| 3225 |
public static String opToPermission(@NonNull String op) { |
| 3226 |
return opToPermission(strOpToOp(op)); |
| 3227 |
} |
| 3228 |
|
| 3229 |
|
| 3230 |
|
| 3231 |
|
| 3232 |
|
| 3233 |
public static String opToRestriction(int op) { |
| 3234 |
return sOpRestrictions[op]; |
| 3235 |
} |
| 3236 |
|
| 3237 |
|
| 3238 |
|
| 3239 |
|
| 3240 |
|
| 3241 |
|
| 3242 |
|
| 3243 |
@UnsupportedAppUsage |
| 3244 |
@TestApi |
| 3245 |
public static int permissionToOpCode(String permission) { |
| 3246 |
Integer boxedOpCode = sPermToOp.get(permission); |
| 3247 |
return boxedOpCode != null ? boxedOpCode : OP_NONE; |
| 3248 |
} |
| 3249 |
|
| 3250 |
|
| 3251 |
|
| 3252 |
|
| 3253 |
|
| 3254 |
|
| 3255 |
public static RestrictionBypass opAllowSystemBypassRestriction(int op) { |
| 3256 |
return sOpAllowSystemRestrictionBypass[op]; |
| 3257 |
} |
| 3258 |
|
| 3259 |
|
| 3260 |
|
| 3261 |
|
| 3262 |
|
| 3263 |
public static @Mode int opToDefaultMode(int op) { |
| 3264 |
return sOpDefaultMode[op]; |
| 3265 |
} |
| 3266 |
|
| 3267 |
|
| 3268 |
|
| 3269 |
|
| 3270 |
|
| 3271 |
|
| 3272 |
|
| 3273 |
|
| 3274 |
|
| 3275 |
|
| 3276 |
@SystemApi |
| 3277 |
public static int opToDefaultMode(@NonNull String appOp) { |
| 3278 |
return opToDefaultMode(strOpToOp(appOp)); |
| 3279 |
} |
| 3280 |
|
| 3281 |
|
| 3282 |
|
| 3283 |
|
| 3284 |
|
| 3285 |
public static String modeToName(@Mode int mode) { |
| 3286 |
if (mode >= 0 && mode < MODE_NAMES.length) { |
| 3287 |
return MODE_NAMES[mode]; |
| 3288 |
} |
| 3289 |
return "mode=" + mode; |
| 3290 |
} |
| 3291 |
|
| 3292 |
|
| 3293 |
|
| 3294 |
|
| 3295 |
|
| 3296 |
public static boolean opRestrictsRead(int op) { |
| 3297 |
return sOpRestrictRead[op]; |
| 3298 |
} |
| 3299 |
|
| 3300 |
|
| 3301 |
|
| 3302 |
|
| 3303 |
|
| 3304 |
public static boolean opAllowsReset(int op) { |
| 3305 |
return !sOpDisableReset[op]; |
| 3306 |
} |
| 3307 |
|
| 3308 |
|
| 3309 |
|
| 3310 |
|
| 3311 |
|
| 3312 |
|
| 3313 |
|
| 3314 |
|
| 3315 |
|
| 3316 |
|
| 3317 |
|
| 3318 |
|
| 3319 |
|
| 3320 |
|
| 3321 |
|
| 3322 |
public static @NonNull String toReceiverId(@Nullable Object obj) { |
| 3323 |
if (obj == null) { |
| 3324 |
return "null"; |
| 3325 |
} else if (obj instanceof PendingIntent) { |
| 3326 |
return toReceiverId((PendingIntent) obj); |
| 3327 |
} else { |
| 3328 |
return obj.getClass().getName() + "@" + System.identityHashCode(obj); |
| 3329 |
} |
| 3330 |
} |
| 3331 |
|
| 3332 |
|
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
|
| 3337 |
|
| 3338 |
|
| 3339 |
|
| 3340 |
|
| 3341 |
|
| 3342 |
|
| 3343 |
|
| 3344 |
public static @NonNull String toReceiverId(@NonNull PendingIntent pendingIntent) { |
| 3345 |
return pendingIntent.getTag(""); |
| 3346 |
} |
| 3347 |
|
| 3348 |
|
| 3349 |
|
| 3350 |
|
| 3351 |
|
| 3352 |
|
| 3353 |
public static class RestrictionBypass { |
| 3354 |
|
| 3355 |
public boolean isSystemUid; |
| 3356 |
|
| 3357 |
|
| 3358 |
public boolean isPrivileged; |
| 3359 |
|
| 3360 |
|
| 3361 |
|
| 3362 |
|
| 3363 |
|
| 3364 |
public boolean isRecordAudioRestrictionExcept; |
| 3365 |
|
| 3366 |
public RestrictionBypass(boolean isSystemUid, boolean isPrivileged, |
| 3367 |
boolean isRecordAudioRestrictionExcept) { |
| 3368 |
this.isSystemUid = isSystemUid; |
| 3369 |
this.isPrivileged = isPrivileged; |
| 3370 |
this.isRecordAudioRestrictionExcept = isRecordAudioRestrictionExcept; |
| 3371 |
} |
| 3372 |
|
| 3373 |
public static RestrictionBypass UNRESTRICTED = new RestrictionBypass(false, true, true); |
| 3374 |
} |
| 3375 |
|
| 3376 |
|
| 3377 |
|
| 3378 |
|
| 3379 |
|
| 3380 |
@SystemApi |
| 3381 |
public static final class PackageOps implements Parcelable { |
| 3382 |
private final String mPackageName; |
| 3383 |
private final int mUid; |
| 3384 |
private final List<OpEntry> mEntries; |
| 3385 |
|
| 3386 |
|
| 3387 |
|
| 3388 |
|
| 3389 |
@UnsupportedAppUsage |
| 3390 |
public PackageOps(String packageName, int uid, List<OpEntry> entries) { |
| 3391 |
mPackageName = packageName; |
| 3392 |
mUid = uid; |
| 3393 |
mEntries = entries; |
| 3394 |
} |
| 3395 |
|
| 3396 |
|
| 3397 |
|
| 3398 |
|
| 3399 |
public @NonNull String getPackageName() { |
| 3400 |
return mPackageName; |
| 3401 |
} |
| 3402 |
|
| 3403 |
|
| 3404 |
|
| 3405 |
|
| 3406 |
public int getUid() { |
| 3407 |
return mUid; |
| 3408 |
} |
| 3409 |
|
| 3410 |
|
| 3411 |
|
| 3412 |
|
| 3413 |
public @NonNull List<OpEntry> getOps() { |
| 3414 |
return mEntries; |
| 3415 |
} |
| 3416 |
|
| 3417 |
@Override |
| 3418 |
public int describeContents() { |
| 3419 |
return 0; |
| 3420 |
} |
| 3421 |
|
| 3422 |
@Override |
| 3423 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 3424 |
dest.writeString(mPackageName); |
| 3425 |
dest.writeInt(mUid); |
| 3426 |
dest.writeInt(mEntries.size()); |
| 3427 |
for (int i=0; i<mEntries.size(); i++) { |
| 3428 |
mEntries.get(i).writeToParcel(dest, flags); |
| 3429 |
} |
| 3430 |
} |
| 3431 |
|
| 3432 |
PackageOps(Parcel source) { |
| 3433 |
mPackageName = source.readString(); |
| 3434 |
mUid = source.readInt(); |
| 3435 |
mEntries = new ArrayList<OpEntry>(); |
| 3436 |
final int N = source.readInt(); |
| 3437 |
for (int i=0; i<N; i++) { |
| 3438 |
mEntries.add(OpEntry.CREATOR.createFromParcel(source)); |
| 3439 |
} |
| 3440 |
} |
| 3441 |
|
| 3442 |
public static final @android.annotation.NonNull Creator<PackageOps> CREATOR = new Creator<PackageOps>() { |
| 3443 |
@Override public PackageOps createFromParcel(Parcel source) { |
| 3444 |
return new PackageOps(source); |
| 3445 |
} |
| 3446 |
|
| 3447 |
@Override public PackageOps[] newArray(int size) { |
| 3448 |
return new PackageOps[size]; |
| 3449 |
} |
| 3450 |
}; |
| 3451 |
} |
| 3452 |
|
| 3453 |
|
| 3454 |
|
| 3455 |
|
| 3456 |
|
| 3457 |
|
| 3458 |
@SystemApi |
| 3459 |
|
| 3460 |
|
| 3461 |
public static final class OpEventProxyInfo implements Parcelable { |
| 3462 |
|
| 3463 |
private @IntRange(from = 0) int mUid; |
| 3464 |
|
| 3465 |
private @Nullable String mPackageName; |
| 3466 |
|
| 3467 |
private @Nullable String mAttributionTag; |
| 3468 |
|
| 3469 |
|
| 3470 |
|
| 3471 |
|
| 3472 |
|
| 3473 |
|
| 3474 |
|
| 3475 |
|
| 3476 |
|
| 3477 |
|
| 3478 |
public void reinit(@IntRange(from = 0) int uid, @Nullable String packageName, |
| 3479 |
@Nullable String attributionTag) { |
| 3480 |
mUid = Preconditions.checkArgumentNonnegative(uid); |
| 3481 |
mPackageName = packageName; |
| 3482 |
mAttributionTag = attributionTag; |
| 3483 |
} |
| 3484 |
|
| 3485 |
|
| 3486 |
|
| 3487 |
|
| 3488 |
|
| 3489 |
|
| 3490 |
|
| 3491 |
|
| 3492 |
|
| 3493 |
|
| 3494 |
|
| 3495 |
|
| 3496 |
|
| 3497 |
|
| 3498 |
|
| 3499 |
|
| 3500 |
|
| 3501 |
|
| 3502 |
|
| 3503 |
|
| 3504 |
|
| 3505 |
|
| 3506 |
|
| 3507 |
|
| 3508 |
|
| 3509 |
|
| 3510 |
|
| 3511 |
@DataClass.Generated.Member |
| 3512 |
public OpEventProxyInfo( |
| 3513 |
@IntRange(from = 0) int uid, |
| 3514 |
@Nullable String packageName, |
| 3515 |
@Nullable String attributionTag) { |
| 3516 |
this.mUid = uid; |
| 3517 |
com.android.internal.util.AnnotationValidations.validate( |
| 3518 |
IntRange.class, null, mUid, |
| 3519 |
"from", 0); |
| 3520 |
this.mPackageName = packageName; |
| 3521 |
this.mAttributionTag = attributionTag; |
| 3522 |
|
| 3523 |
|
| 3524 |
} |
| 3525 |
|
| 3526 |
|
| 3527 |
|
| 3528 |
|
| 3529 |
|
| 3530 |
|
| 3531 |
@DataClass.Generated.Member |
| 3532 |
public OpEventProxyInfo(@NonNull OpEventProxyInfo orig) { |
| 3533 |
mUid = orig.mUid; |
| 3534 |
mPackageName = orig.mPackageName; |
| 3535 |
mAttributionTag = orig.mAttributionTag; |
| 3536 |
} |
| 3537 |
|
| 3538 |
|
| 3539 |
|
| 3540 |
|
| 3541 |
@DataClass.Generated.Member |
| 3542 |
public @IntRange(from = 0) int getUid() { |
| 3543 |
return mUid; |
| 3544 |
} |
| 3545 |
|
| 3546 |
|
| 3547 |
|
| 3548 |
|
| 3549 |
@DataClass.Generated.Member |
| 3550 |
public @Nullable String getPackageName() { |
| 3551 |
return mPackageName; |
| 3552 |
} |
| 3553 |
|
| 3554 |
|
| 3555 |
|
| 3556 |
|
| 3557 |
@DataClass.Generated.Member |
| 3558 |
public @Nullable String getAttributionTag() { |
| 3559 |
return mAttributionTag; |
| 3560 |
} |
| 3561 |
|
| 3562 |
@Override |
| 3563 |
@DataClass.Generated.Member |
| 3564 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 3565 |
|
| 3566 |
|
| 3567 |
|
| 3568 |
byte flg = 0; |
| 3569 |
if (mPackageName != null) flg |= 0x2; |
| 3570 |
if (mAttributionTag != null) flg |= 0x4; |
| 3571 |
dest.writeByte(flg); |
| 3572 |
dest.writeInt(mUid); |
| 3573 |
if (mPackageName != null) dest.writeString(mPackageName); |
| 3574 |
if (mAttributionTag != null) dest.writeString(mAttributionTag); |
| 3575 |
} |
| 3576 |
|
| 3577 |
@Override |
| 3578 |
@DataClass.Generated.Member |
| 3579 |
public int describeContents() { return 0; } |
| 3580 |
|
| 3581 |
|
| 3582 |
@SuppressWarnings({"unchecked", "RedundantCast"}) |
| 3583 |
@DataClass.Generated.Member |
| 3584 |
OpEventProxyInfo(@NonNull Parcel in) { |
| 3585 |
|
| 3586 |
|
| 3587 |
|
| 3588 |
byte flg = in.readByte(); |
| 3589 |
int uid = in.readInt(); |
| 3590 |
String packageName = (flg & 0x2) == 0 ? null : in.readString(); |
| 3591 |
String attributionTag = (flg & 0x4) == 0 ? null : in.readString(); |
| 3592 |
|
| 3593 |
this.mUid = uid; |
| 3594 |
com.android.internal.util.AnnotationValidations.validate( |
| 3595 |
IntRange.class, null, mUid, |
| 3596 |
"from", 0); |
| 3597 |
this.mPackageName = packageName; |
| 3598 |
this.mAttributionTag = attributionTag; |
| 3599 |
|
| 3600 |
|
| 3601 |
} |
| 3602 |
|
| 3603 |
@DataClass.Generated.Member |
| 3604 |
public static final @NonNull Parcelable.Creator<OpEventProxyInfo> CREATOR |
| 3605 |
= new Parcelable.Creator<OpEventProxyInfo>() { |
| 3606 |
@Override |
| 3607 |
public OpEventProxyInfo[] newArray(int size) { |
| 3608 |
return new OpEventProxyInfo[size]; |
| 3609 |
} |
| 3610 |
|
| 3611 |
@Override |
| 3612 |
public OpEventProxyInfo createFromParcel(@NonNull Parcel in) { |
| 3613 |
return new OpEventProxyInfo(in); |
| 3614 |
} |
| 3615 |
}; |
| 3616 |
|
| 3617 |
|
| 3618 |
|
| 3619 |
|
| 3620 |
|
| 3621 |
|
| 3622 |
|
| 3623 |
|
| 3624 |
|
| 3625 |
|
| 3626 |
|
| 3627 |
|
| 3628 |
|
| 3629 |
|
| 3630 |
} |
| 3631 |
|
| 3632 |
|
| 3633 |
|
| 3634 |
|
| 3635 |
|
| 3636 |
|
| 3637 |
|
| 3638 |
public static final class NoteOpEvent implements Parcelable { |
| 3639 |
|
| 3640 |
private @IntRange(from = 0) long mNoteTime; |
| 3641 |
|
| 3642 |
private @IntRange(from = -1) long mDuration; |
| 3643 |
|
| 3644 |
private @Nullable OpEventProxyInfo mProxy; |
| 3645 |
|
| 3646 |
|
| 3647 |
|
| 3648 |
|
| 3649 |
|
| 3650 |
|
| 3651 |
|
| 3652 |
|
| 3653 |
|
| 3654 |
|
| 3655 |
public void reinit(@IntRange(from = 0) long noteTime, |
| 3656 |
@IntRange(from = -1) long duration, |
| 3657 |
@Nullable OpEventProxyInfo proxy, |
| 3658 |
@NonNull Pools.Pool<OpEventProxyInfo> proxyPool) { |
| 3659 |
mNoteTime = Preconditions.checkArgumentNonnegative(noteTime); |
| 3660 |
mDuration = Preconditions.checkArgumentInRange(duration, -1L, Long.MAX_VALUE, |
| 3661 |
"duration"); |
| 3662 |
|
| 3663 |
if (mProxy != null) { |
| 3664 |
proxyPool.release(mProxy); |
| 3665 |
} |
| 3666 |
mProxy = proxy; |
| 3667 |
} |
| 3668 |
|
| 3669 |
|
| 3670 |
|
| 3671 |
|
| 3672 |
|
| 3673 |
|
| 3674 |
public NoteOpEvent(@NonNull NoteOpEvent original) { |
| 3675 |
this(original.mNoteTime, original.mDuration, |
| 3676 |
original.mProxy != null ? new OpEventProxyInfo(original.mProxy) : null); |
| 3677 |
} |
| 3678 |
|
| 3679 |
|
| 3680 |
|
| 3681 |
|
| 3682 |
|
| 3683 |
|
| 3684 |
|
| 3685 |
|
| 3686 |
|
| 3687 |
|
| 3688 |
|
| 3689 |
|
| 3690 |
|
| 3691 |
|
| 3692 |
|
| 3693 |
|
| 3694 |
|
| 3695 |
|
| 3696 |
|
| 3697 |
|
| 3698 |
|
| 3699 |
|
| 3700 |
|
| 3701 |
|
| 3702 |
|
| 3703 |
|
| 3704 |
@DataClass.Generated.Member |
| 3705 |
public NoteOpEvent( |
| 3706 |
@IntRange(from = 0) long noteTime, |
| 3707 |
@IntRange(from = -1) long duration, |
| 3708 |
@Nullable OpEventProxyInfo proxy) { |
| 3709 |
this.mNoteTime = noteTime; |
| 3710 |
com.android.internal.util.AnnotationValidations.validate( |
| 3711 |
IntRange.class, null, mNoteTime, |
| 3712 |
"from", 0); |
| 3713 |
this.mDuration = duration; |
| 3714 |
com.android.internal.util.AnnotationValidations.validate( |
| 3715 |
IntRange.class, null, mDuration, |
| 3716 |
"from", -1); |
| 3717 |
this.mProxy = proxy; |
| 3718 |
|
| 3719 |
|
| 3720 |
} |
| 3721 |
|
| 3722 |
|
| 3723 |
|
| 3724 |
|
| 3725 |
@DataClass.Generated.Member |
| 3726 |
public @IntRange(from = 0) long getNoteTime() { |
| 3727 |
return mNoteTime; |
| 3728 |
} |
| 3729 |
|
| 3730 |
|
| 3731 |
|
| 3732 |
|
| 3733 |
@DataClass.Generated.Member |
| 3734 |
public @IntRange(from = -1) long getDuration() { |
| 3735 |
return mDuration; |
| 3736 |
} |
| 3737 |
|
| 3738 |
|
| 3739 |
|
| 3740 |
|
| 3741 |
@DataClass.Generated.Member |
| 3742 |
public @Nullable OpEventProxyInfo getProxy() { |
| 3743 |
return mProxy; |
| 3744 |
} |
| 3745 |
|
| 3746 |
@Override |
| 3747 |
@DataClass.Generated.Member |
| 3748 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 3749 |
|
| 3750 |
|
| 3751 |
|
| 3752 |
byte flg = 0; |
| 3753 |
if (mProxy != null) flg |= 0x4; |
| 3754 |
dest.writeByte(flg); |
| 3755 |
dest.writeLong(mNoteTime); |
| 3756 |
dest.writeLong(mDuration); |
| 3757 |
if (mProxy != null) dest.writeTypedObject(mProxy, flags); |
| 3758 |
} |
| 3759 |
|
| 3760 |
@Override |
| 3761 |
@DataClass.Generated.Member |
| 3762 |
public int describeContents() { return 0; } |
| 3763 |
|
| 3764 |
|
| 3765 |
@SuppressWarnings({"unchecked", "RedundantCast"}) |
| 3766 |
@DataClass.Generated.Member |
| 3767 |
NoteOpEvent(@NonNull Parcel in) { |
| 3768 |
|
| 3769 |
|
| 3770 |
|
| 3771 |
byte flg = in.readByte(); |
| 3772 |
long noteTime = in.readLong(); |
| 3773 |
long duration = in.readLong(); |
| 3774 |
OpEventProxyInfo proxy = (flg & 0x4) == 0 ? null : (OpEventProxyInfo) in.readTypedObject(OpEventProxyInfo.CREATOR); |
| 3775 |
|
| 3776 |
this.mNoteTime = noteTime; |
| 3777 |
com.android.internal.util.AnnotationValidations.validate( |
| 3778 |
IntRange.class, null, mNoteTime, |
| 3779 |
"from", 0); |
| 3780 |
this.mDuration = duration; |
| 3781 |
com.android.internal.util.AnnotationValidations.validate( |
| 3782 |
IntRange.class, null, mDuration, |
| 3783 |
"from", -1); |
| 3784 |
this.mProxy = proxy; |
| 3785 |
|
| 3786 |
|
| 3787 |
} |
| 3788 |
|
| 3789 |
@DataClass.Generated.Member |
| 3790 |
public static final @NonNull Parcelable.Creator<NoteOpEvent> CREATOR |
| 3791 |
= new Parcelable.Creator<NoteOpEvent>() { |
| 3792 |
@Override |
| 3793 |
public NoteOpEvent[] newArray(int size) { |
| 3794 |
return new NoteOpEvent[size]; |
| 3795 |
} |
| 3796 |
|
| 3797 |
@Override |
| 3798 |
public NoteOpEvent createFromParcel(@NonNull Parcel in) { |
| 3799 |
return new NoteOpEvent(in); |
| 3800 |
} |
| 3801 |
}; |
| 3802 |
|
| 3803 |
|
| 3804 |
|
| 3805 |
|
| 3806 |
|
| 3807 |
|
| 3808 |
|
| 3809 |
|
| 3810 |
|
| 3811 |
|
| 3812 |
|
| 3813 |
|
| 3814 |
|
| 3815 |
|
| 3816 |
|
| 3817 |
} |
| 3818 |
|
| 3819 |
|
| 3820 |
|
| 3821 |
|
| 3822 |
|
| 3823 |
|
| 3824 |
|
| 3825 |
@SystemApi |
| 3826 |
@Immutable |
| 3827 |
|
| 3828 |
@DataClass.Suppress({"getAccessEvents", "getRejectEvents", "getOp"}) |
| 3829 |
public static final class AttributedOpEntry implements Parcelable { |
| 3830 |
|
| 3831 |
private final @IntRange(from = 0, to = _NUM_OP - 1) int mOp; |
| 3832 |
|
| 3833 |
private final boolean mRunning; |
| 3834 |
|
| 3835 |
@DataClass.ParcelWith(LongSparseArrayParceling.class) |
| 3836 |
private final @Nullable LongSparseArray<NoteOpEvent> mAccessEvents; |
| 3837 |
|
| 3838 |
@DataClass.ParcelWith(LongSparseArrayParceling.class) |
| 3839 |
private final @Nullable LongSparseArray<NoteOpEvent> mRejectEvents; |
| 3840 |
|
| 3841 |
private AttributedOpEntry(@NonNull AttributedOpEntry other) { |
| 3842 |
mOp = other.mOp; |
| 3843 |
mRunning = other.mRunning; |
| 3844 |
mAccessEvents = other.mAccessEvents == null ? null : other.mAccessEvents.clone(); |
| 3845 |
mRejectEvents = other.mRejectEvents == null ? null : other.mRejectEvents.clone(); |
| 3846 |
} |
| 3847 |
|
| 3848 |
|
| 3849 |
|
| 3850 |
|
| 3851 |
|
| 3852 |
|
| 3853 |
public @NonNull ArraySet<Long> collectKeys() { |
| 3854 |
ArraySet<Long> keys = new ArraySet<>(); |
| 3855 |
|
| 3856 |
if (mAccessEvents != null) { |
| 3857 |
int numEvents = mAccessEvents.size(); |
| 3858 |
for (int i = 0; i < numEvents; i++) { |
| 3859 |
keys.add(mAccessEvents.keyAt(i)); |
| 3860 |
} |
| 3861 |
} |
| 3862 |
|
| 3863 |
if (mRejectEvents != null) { |
| 3864 |
int numEvents = mRejectEvents.size(); |
| 3865 |
for (int i = 0; i < numEvents; i++) { |
| 3866 |
keys.add(mRejectEvents.keyAt(i)); |
| 3867 |
} |
| 3868 |
} |
| 3869 |
|
| 3870 |
return keys; |
| 3871 |
} |
| 3872 |
|
| 3873 |
|
| 3874 |
|
| 3875 |
|
| 3876 |
|
| 3877 |
|
| 3878 |
|
| 3879 |
|
| 3880 |
|
| 3881 |
|
| 3882 |
|
| 3883 |
|
| 3884 |
|
| 3885 |
|
| 3886 |
public long getLastAccessTime(@OpFlags int flags) { |
| 3887 |
return getLastAccessTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 3888 |
} |
| 3889 |
|
| 3890 |
|
| 3891 |
|
| 3892 |
|
| 3893 |
|
| 3894 |
|
| 3895 |
|
| 3896 |
|
| 3897 |
|
| 3898 |
|
| 3899 |
|
| 3900 |
|
| 3901 |
|
| 3902 |
|
| 3903 |
public long getLastAccessForegroundTime(@OpFlags int flags) { |
| 3904 |
return getLastAccessTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 3905 |
flags); |
| 3906 |
} |
| 3907 |
|
| 3908 |
|
| 3909 |
|
| 3910 |
|
| 3911 |
|
| 3912 |
|
| 3913 |
|
| 3914 |
|
| 3915 |
|
| 3916 |
|
| 3917 |
|
| 3918 |
|
| 3919 |
|
| 3920 |
|
| 3921 |
public long getLastAccessBackgroundTime(@OpFlags int flags) { |
| 3922 |
return getLastAccessTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 3923 |
flags); |
| 3924 |
} |
| 3925 |
|
| 3926 |
|
| 3927 |
|
| 3928 |
|
| 3929 |
|
| 3930 |
|
| 3931 |
|
| 3932 |
|
| 3933 |
private @Nullable NoteOpEvent getLastAccessEvent(@UidState int fromUidState, |
| 3934 |
@UidState int toUidState, @OpFlags int flags) { |
| 3935 |
return getLastEvent(mAccessEvents, fromUidState, toUidState, flags); |
| 3936 |
} |
| 3937 |
|
| 3938 |
|
| 3939 |
|
| 3940 |
|
| 3941 |
|
| 3942 |
|
| 3943 |
|
| 3944 |
|
| 3945 |
|
| 3946 |
|
| 3947 |
|
| 3948 |
|
| 3949 |
|
| 3950 |
|
| 3951 |
|
| 3952 |
|
| 3953 |
public long getLastAccessTime(@UidState int fromUidState, @UidState int toUidState, |
| 3954 |
@OpFlags int flags) { |
| 3955 |
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags); |
| 3956 |
if (lastEvent == null) { |
| 3957 |
return -1; |
| 3958 |
} |
| 3959 |
|
| 3960 |
return lastEvent.getNoteTime(); |
| 3961 |
} |
| 3962 |
|
| 3963 |
|
| 3964 |
|
| 3965 |
|
| 3966 |
|
| 3967 |
|
| 3968 |
|
| 3969 |
|
| 3970 |
|
| 3971 |
|
| 3972 |
|
| 3973 |
|
| 3974 |
|
| 3975 |
|
| 3976 |
public long getLastRejectTime(@OpFlags int flags) { |
| 3977 |
return getLastRejectTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 3978 |
} |
| 3979 |
|
| 3980 |
|
| 3981 |
|
| 3982 |
|
| 3983 |
|
| 3984 |
|
| 3985 |
|
| 3986 |
|
| 3987 |
|
| 3988 |
|
| 3989 |
|
| 3990 |
|
| 3991 |
|
| 3992 |
|
| 3993 |
public long getLastRejectForegroundTime(@OpFlags int flags) { |
| 3994 |
return getLastRejectTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 3995 |
flags); |
| 3996 |
} |
| 3997 |
|
| 3998 |
|
| 3999 |
|
| 4000 |
|
| 4001 |
|
| 4002 |
|
| 4003 |
|
| 4004 |
|
| 4005 |
|
| 4006 |
|
| 4007 |
|
| 4008 |
|
| 4009 |
|
| 4010 |
|
| 4011 |
public long getLastRejectBackgroundTime(@OpFlags int flags) { |
| 4012 |
return getLastRejectTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 4013 |
flags); |
| 4014 |
} |
| 4015 |
|
| 4016 |
|
| 4017 |
|
| 4018 |
|
| 4019 |
|
| 4020 |
|
| 4021 |
|
| 4022 |
|
| 4023 |
|
| 4024 |
|
| 4025 |
|
| 4026 |
|
| 4027 |
|
| 4028 |
private @Nullable NoteOpEvent getLastRejectEvent(@UidState int fromUidState, |
| 4029 |
@UidState int toUidState, @OpFlags int flags) { |
| 4030 |
return getLastEvent(mRejectEvents, fromUidState, toUidState, flags); |
| 4031 |
} |
| 4032 |
|
| 4033 |
|
| 4034 |
|
| 4035 |
|
| 4036 |
|
| 4037 |
|
| 4038 |
|
| 4039 |
|
| 4040 |
|
| 4041 |
|
| 4042 |
|
| 4043 |
|
| 4044 |
|
| 4045 |
|
| 4046 |
|
| 4047 |
|
| 4048 |
|
| 4049 |
public long getLastRejectTime(@UidState int fromUidState, @UidState int toUidState, |
| 4050 |
@OpFlags int flags) { |
| 4051 |
NoteOpEvent lastEvent = getLastRejectEvent(fromUidState, toUidState, flags); |
| 4052 |
if (lastEvent == null) { |
| 4053 |
return -1; |
| 4054 |
} |
| 4055 |
|
| 4056 |
return lastEvent.getNoteTime(); |
| 4057 |
} |
| 4058 |
|
| 4059 |
|
| 4060 |
|
| 4061 |
|
| 4062 |
|
| 4063 |
|
| 4064 |
|
| 4065 |
|
| 4066 |
|
| 4067 |
|
| 4068 |
|
| 4069 |
|
| 4070 |
|
| 4071 |
public long getLastDuration(@OpFlags int flags) { |
| 4072 |
return getLastDuration(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 4073 |
} |
| 4074 |
|
| 4075 |
|
| 4076 |
|
| 4077 |
|
| 4078 |
|
| 4079 |
|
| 4080 |
|
| 4081 |
|
| 4082 |
|
| 4083 |
|
| 4084 |
|
| 4085 |
|
| 4086 |
|
| 4087 |
public long getLastForegroundDuration(@OpFlags int flags) { |
| 4088 |
return getLastDuration(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 4089 |
flags); |
| 4090 |
} |
| 4091 |
|
| 4092 |
|
| 4093 |
|
| 4094 |
|
| 4095 |
|
| 4096 |
|
| 4097 |
|
| 4098 |
|
| 4099 |
|
| 4100 |
|
| 4101 |
|
| 4102 |
|
| 4103 |
|
| 4104 |
public long getLastBackgroundDuration(@OpFlags int flags) { |
| 4105 |
return getLastDuration(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 4106 |
flags); |
| 4107 |
} |
| 4108 |
|
| 4109 |
|
| 4110 |
|
| 4111 |
|
| 4112 |
|
| 4113 |
|
| 4114 |
|
| 4115 |
|
| 4116 |
|
| 4117 |
|
| 4118 |
|
| 4119 |
|
| 4120 |
|
| 4121 |
|
| 4122 |
|
| 4123 |
|
| 4124 |
public long getLastDuration(@UidState int fromUidState, @UidState int toUidState, |
| 4125 |
@OpFlags int flags) { |
| 4126 |
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);; |
| 4127 |
if (lastEvent == null) { |
| 4128 |
return -1; |
| 4129 |
} |
| 4130 |
|
| 4131 |
return lastEvent.getDuration(); |
| 4132 |
} |
| 4133 |
|
| 4134 |
|
| 4135 |
|
| 4136 |
|
| 4137 |
|
| 4138 |
|
| 4139 |
|
| 4140 |
|
| 4141 |
|
| 4142 |
|
| 4143 |
|
| 4144 |
|
| 4145 |
|
| 4146 |
|
| 4147 |
public @Nullable OpEventProxyInfo getLastProxyInfo(@OpFlags int flags) { |
| 4148 |
return getLastProxyInfo(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 4149 |
} |
| 4150 |
|
| 4151 |
|
| 4152 |
|
| 4153 |
|
| 4154 |
|
| 4155 |
|
| 4156 |
|
| 4157 |
|
| 4158 |
|
| 4159 |
|
| 4160 |
|
| 4161 |
|
| 4162 |
|
| 4163 |
|
| 4164 |
public @Nullable OpEventProxyInfo getLastForegroundProxyInfo(@OpFlags int flags) { |
| 4165 |
return getLastProxyInfo(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 4166 |
flags); |
| 4167 |
} |
| 4168 |
|
| 4169 |
|
| 4170 |
|
| 4171 |
|
| 4172 |
|
| 4173 |
|
| 4174 |
|
| 4175 |
|
| 4176 |
|
| 4177 |
|
| 4178 |
|
| 4179 |
|
| 4180 |
|
| 4181 |
|
| 4182 |
public @Nullable OpEventProxyInfo getLastBackgroundProxyInfo(@OpFlags int flags) { |
| 4183 |
return getLastProxyInfo(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 4184 |
flags); |
| 4185 |
} |
| 4186 |
|
| 4187 |
|
| 4188 |
|
| 4189 |
|
| 4190 |
|
| 4191 |
|
| 4192 |
|
| 4193 |
|
| 4194 |
|
| 4195 |
|
| 4196 |
|
| 4197 |
|
| 4198 |
|
| 4199 |
|
| 4200 |
|
| 4201 |
|
| 4202 |
public @Nullable OpEventProxyInfo getLastProxyInfo(@UidState int fromUidState, |
| 4203 |
@UidState int toUidState, @OpFlags int flags) { |
| 4204 |
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags); |
| 4205 |
if (lastEvent == null) { |
| 4206 |
return null; |
| 4207 |
} |
| 4208 |
|
| 4209 |
return lastEvent.getProxy(); |
| 4210 |
} |
| 4211 |
|
| 4212 |
@NonNull |
| 4213 |
String getOpName() { |
| 4214 |
return AppOpsManager.opToPublicName(mOp); |
| 4215 |
} |
| 4216 |
|
| 4217 |
int getOp() { |
| 4218 |
return mOp; |
| 4219 |
} |
| 4220 |
|
| 4221 |
private static class LongSparseArrayParceling implements |
| 4222 |
Parcelling<LongSparseArray<NoteOpEvent>> { |
| 4223 |
@Override |
| 4224 |
public void parcel(@Nullable LongSparseArray<NoteOpEvent> array, @NonNull Parcel dest, |
| 4225 |
int parcelFlags) { |
| 4226 |
if (array == null) { |
| 4227 |
dest.writeInt(-1); |
| 4228 |
return; |
| 4229 |
} |
| 4230 |
|
| 4231 |
int numEntries = array.size(); |
| 4232 |
dest.writeInt(numEntries); |
| 4233 |
|
| 4234 |
for (int i = 0; i < numEntries; i++) { |
| 4235 |
dest.writeLong(array.keyAt(i)); |
| 4236 |
dest.writeParcelable(array.valueAt(i), parcelFlags); |
| 4237 |
} |
| 4238 |
} |
| 4239 |
|
| 4240 |
@Override |
| 4241 |
public @Nullable LongSparseArray<NoteOpEvent> unparcel(@NonNull Parcel source) { |
| 4242 |
int numEntries = source.readInt(); |
| 4243 |
if (numEntries == -1) { |
| 4244 |
return null; |
| 4245 |
} |
| 4246 |
|
| 4247 |
LongSparseArray<NoteOpEvent> array = new LongSparseArray<>(numEntries); |
| 4248 |
|
| 4249 |
for (int i = 0; i < numEntries; i++) { |
| 4250 |
array.put(source.readLong(), source.readParcelable(null, android.app.AppOpsManager.NoteOpEvent.class)); |
| 4251 |
} |
| 4252 |
|
| 4253 |
return array; |
| 4254 |
} |
| 4255 |
} |
| 4256 |
|
| 4257 |
|
| 4258 |
|
| 4259 |
|
| 4260 |
|
| 4261 |
|
| 4262 |
|
| 4263 |
|
| 4264 |
|
| 4265 |
|
| 4266 |
|
| 4267 |
|
| 4268 |
|
| 4269 |
|
| 4270 |
|
| 4271 |
|
| 4272 |
|
| 4273 |
|
| 4274 |
|
| 4275 |
|
| 4276 |
|
| 4277 |
|
| 4278 |
|
| 4279 |
|
| 4280 |
|
| 4281 |
|
| 4282 |
|
| 4283 |
|
| 4284 |
|
| 4285 |
@DataClass.Generated.Member |
| 4286 |
public AttributedOpEntry( |
| 4287 |
@IntRange(from = 0, to = _NUM_OP - 1) int op, |
| 4288 |
boolean running, |
| 4289 |
@Nullable LongSparseArray<NoteOpEvent> accessEvents, |
| 4290 |
@Nullable LongSparseArray<NoteOpEvent> rejectEvents) { |
| 4291 |
this.mOp = op; |
| 4292 |
com.android.internal.util.AnnotationValidations.validate( |
| 4293 |
IntRange.class, null, mOp, |
| 4294 |
"from", 0, |
| 4295 |
"to", _NUM_OP - 1); |
| 4296 |
this.mRunning = running; |
| 4297 |
this.mAccessEvents = accessEvents; |
| 4298 |
this.mRejectEvents = rejectEvents; |
| 4299 |
|
| 4300 |
|
| 4301 |
} |
| 4302 |
|
| 4303 |
|
| 4304 |
|
| 4305 |
|
| 4306 |
@DataClass.Generated.Member |
| 4307 |
public boolean isRunning() { |
| 4308 |
return mRunning; |
| 4309 |
} |
| 4310 |
|
| 4311 |
@DataClass.Generated.Member |
| 4312 |
static Parcelling<LongSparseArray<NoteOpEvent>> sParcellingForAccessEvents = |
| 4313 |
Parcelling.Cache.get( |
| 4314 |
LongSparseArrayParceling.class); |
| 4315 |
static { |
| 4316 |
if (sParcellingForAccessEvents == null) { |
| 4317 |
sParcellingForAccessEvents = Parcelling.Cache.put( |
| 4318 |
new LongSparseArrayParceling()); |
| 4319 |
} |
| 4320 |
} |
| 4321 |
|
| 4322 |
@DataClass.Generated.Member |
| 4323 |
static Parcelling<LongSparseArray<NoteOpEvent>> sParcellingForRejectEvents = |
| 4324 |
Parcelling.Cache.get( |
| 4325 |
LongSparseArrayParceling.class); |
| 4326 |
static { |
| 4327 |
if (sParcellingForRejectEvents == null) { |
| 4328 |
sParcellingForRejectEvents = Parcelling.Cache.put( |
| 4329 |
new LongSparseArrayParceling()); |
| 4330 |
} |
| 4331 |
} |
| 4332 |
|
| 4333 |
@Override |
| 4334 |
@DataClass.Generated.Member |
| 4335 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 4336 |
|
| 4337 |
|
| 4338 |
|
| 4339 |
byte flg = 0; |
| 4340 |
if (mRunning) flg |= 0x2; |
| 4341 |
if (mAccessEvents != null) flg |= 0x4; |
| 4342 |
if (mRejectEvents != null) flg |= 0x8; |
| 4343 |
dest.writeByte(flg); |
| 4344 |
dest.writeInt(mOp); |
| 4345 |
sParcellingForAccessEvents.parcel(mAccessEvents, dest, flags); |
| 4346 |
sParcellingForRejectEvents.parcel(mRejectEvents, dest, flags); |
| 4347 |
} |
| 4348 |
|
| 4349 |
@Override |
| 4350 |
@DataClass.Generated.Member |
| 4351 |
public int describeContents() { return 0; } |
| 4352 |
|
| 4353 |
|
| 4354 |
@SuppressWarnings({"unchecked", "RedundantCast"}) |
| 4355 |
@DataClass.Generated.Member |
| 4356 |
AttributedOpEntry(@NonNull Parcel in) { |
| 4357 |
|
| 4358 |
|
| 4359 |
|
| 4360 |
byte flg = in.readByte(); |
| 4361 |
boolean running = (flg & 0x2) != 0; |
| 4362 |
int op = in.readInt(); |
| 4363 |
LongSparseArray<NoteOpEvent> accessEvents = sParcellingForAccessEvents.unparcel(in); |
| 4364 |
LongSparseArray<NoteOpEvent> rejectEvents = sParcellingForRejectEvents.unparcel(in); |
| 4365 |
|
| 4366 |
this.mOp = op; |
| 4367 |
com.android.internal.util.AnnotationValidations.validate( |
| 4368 |
IntRange.class, null, mOp, |
| 4369 |
"from", 0, |
| 4370 |
"to", _NUM_OP - 1); |
| 4371 |
this.mRunning = running; |
| 4372 |
this.mAccessEvents = accessEvents; |
| 4373 |
this.mRejectEvents = rejectEvents; |
| 4374 |
|
| 4375 |
|
| 4376 |
} |
| 4377 |
|
| 4378 |
@DataClass.Generated.Member |
| 4379 |
public static final @NonNull Parcelable.Creator<AttributedOpEntry> CREATOR |
| 4380 |
= new Parcelable.Creator<AttributedOpEntry>() { |
| 4381 |
@Override |
| 4382 |
public AttributedOpEntry[] newArray(int size) { |
| 4383 |
return new AttributedOpEntry[size]; |
| 4384 |
} |
| 4385 |
|
| 4386 |
@Override |
| 4387 |
public AttributedOpEntry createFromParcel(@NonNull Parcel in) { |
| 4388 |
return new AttributedOpEntry(in); |
| 4389 |
} |
| 4390 |
}; |
| 4391 |
|
| 4392 |
|
| 4393 |
|
| 4394 |
|
| 4395 |
|
| 4396 |
|
| 4397 |
|
| 4398 |
|
| 4399 |
|
| 4400 |
|
| 4401 |
|
| 4402 |
|
| 4403 |
|
| 4404 |
|
| 4405 |
|
| 4406 |
} |
| 4407 |
|
| 4408 |
|
| 4409 |
|
| 4410 |
|
| 4411 |
|
| 4412 |
|
| 4413 |
|
| 4414 |
@Immutable |
| 4415 |
@SystemApi |
| 4416 |
|
| 4417 |
public static final class OpEntry implements Parcelable { |
| 4418 |
|
| 4419 |
private final @IntRange(from = 0, to = _NUM_OP - 1) int mOp; |
| 4420 |
|
| 4421 |
private final @Mode int mMode; |
| 4422 |
|
| 4423 |
private final @NonNull Map<String, AttributedOpEntry> mAttributedOpEntries; |
| 4424 |
|
| 4425 |
|
| 4426 |
|
| 4427 |
|
| 4428 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, publicAlternatives = "{@code " |
| 4429 |
+ "#getOpStr()}") |
| 4430 |
public int getOp() { |
| 4431 |
return mOp; |
| 4432 |
} |
| 4433 |
|
| 4434 |
|
| 4435 |
|
| 4436 |
|
| 4437 |
public @NonNull String getOpStr() { |
| 4438 |
return sOpToString[mOp]; |
| 4439 |
} |
| 4440 |
|
| 4441 |
|
| 4442 |
|
| 4443 |
|
| 4444 |
|
| 4445 |
|
| 4446 |
@Deprecated |
| 4447 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, publicAlternatives = "{@code " |
| 4448 |
+ "#getLastAccessTime(int)}") |
| 4449 |
public long getTime() { |
| 4450 |
return getLastAccessTime(OP_FLAGS_ALL); |
| 4451 |
} |
| 4452 |
|
| 4453 |
|
| 4454 |
|
| 4455 |
|
| 4456 |
|
| 4457 |
|
| 4458 |
|
| 4459 |
|
| 4460 |
|
| 4461 |
|
| 4462 |
|
| 4463 |
|
| 4464 |
|
| 4465 |
|
| 4466 |
public long getLastAccessTime(@OpFlags int flags) { |
| 4467 |
return getLastAccessTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 4468 |
} |
| 4469 |
|
| 4470 |
|
| 4471 |
|
| 4472 |
|
| 4473 |
|
| 4474 |
|
| 4475 |
|
| 4476 |
|
| 4477 |
|
| 4478 |
|
| 4479 |
|
| 4480 |
|
| 4481 |
|
| 4482 |
|
| 4483 |
public long getLastAccessForegroundTime(@OpFlags int flags) { |
| 4484 |
return getLastAccessTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 4485 |
flags); |
| 4486 |
} |
| 4487 |
|
| 4488 |
|
| 4489 |
|
| 4490 |
|
| 4491 |
|
| 4492 |
|
| 4493 |
|
| 4494 |
|
| 4495 |
|
| 4496 |
|
| 4497 |
|
| 4498 |
|
| 4499 |
|
| 4500 |
|
| 4501 |
public long getLastAccessBackgroundTime(@OpFlags int flags) { |
| 4502 |
return getLastAccessTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 4503 |
flags); |
| 4504 |
} |
| 4505 |
|
| 4506 |
|
| 4507 |
|
| 4508 |
|
| 4509 |
|
| 4510 |
|
| 4511 |
|
| 4512 |
|
| 4513 |
private @Nullable NoteOpEvent getLastAccessEvent(@UidState int fromUidState, |
| 4514 |
@UidState int toUidState, @OpFlags int flags) { |
| 4515 |
NoteOpEvent lastAccessEvent = null; |
| 4516 |
for (AttributedOpEntry attributionEntry : mAttributedOpEntries.values()) { |
| 4517 |
NoteOpEvent lastAttributionAccessEvent = attributionEntry.getLastAccessEvent( |
| 4518 |
fromUidState, toUidState, flags); |
| 4519 |
|
| 4520 |
if (lastAccessEvent == null || (lastAttributionAccessEvent != null |
| 4521 |
&& lastAttributionAccessEvent.getNoteTime() |
| 4522 |
> lastAccessEvent.getNoteTime())) { |
| 4523 |
lastAccessEvent = lastAttributionAccessEvent; |
| 4524 |
} |
| 4525 |
} |
| 4526 |
|
| 4527 |
return lastAccessEvent; |
| 4528 |
} |
| 4529 |
|
| 4530 |
|
| 4531 |
|
| 4532 |
|
| 4533 |
|
| 4534 |
|
| 4535 |
|
| 4536 |
|
| 4537 |
|
| 4538 |
|
| 4539 |
|
| 4540 |
|
| 4541 |
|
| 4542 |
|
| 4543 |
|
| 4544 |
|
| 4545 |
public long getLastAccessTime(@UidState int fromUidState, @UidState int toUidState, |
| 4546 |
@OpFlags int flags) { |
| 4547 |
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);; |
| 4548 |
|
| 4549 |
if (lastEvent == null) { |
| 4550 |
return -1; |
| 4551 |
} |
| 4552 |
|
| 4553 |
return lastEvent.getNoteTime(); |
| 4554 |
} |
| 4555 |
|
| 4556 |
|
| 4557 |
|
| 4558 |
|
| 4559 |
|
| 4560 |
|
| 4561 |
@Deprecated |
| 4562 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, publicAlternatives = "{@code " |
| 4563 |
+ "#getLastRejectTime(int)}") |
| 4564 |
public long getRejectTime() { |
| 4565 |
return getLastRejectTime(OP_FLAGS_ALL); |
| 4566 |
} |
| 4567 |
|
| 4568 |
|
| 4569 |
|
| 4570 |
|
| 4571 |
|
| 4572 |
|
| 4573 |
|
| 4574 |
|
| 4575 |
|
| 4576 |
|
| 4577 |
|
| 4578 |
|
| 4579 |
|
| 4580 |
|
| 4581 |
public long getLastRejectTime(@OpFlags int flags) { |
| 4582 |
return getLastRejectTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 4583 |
} |
| 4584 |
|
| 4585 |
|
| 4586 |
|
| 4587 |
|
| 4588 |
|
| 4589 |
|
| 4590 |
|
| 4591 |
|
| 4592 |
|
| 4593 |
|
| 4594 |
|
| 4595 |
|
| 4596 |
|
| 4597 |
|
| 4598 |
public long getLastRejectForegroundTime(@OpFlags int flags) { |
| 4599 |
return getLastRejectTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 4600 |
flags); |
| 4601 |
} |
| 4602 |
|
| 4603 |
|
| 4604 |
|
| 4605 |
|
| 4606 |
|
| 4607 |
|
| 4608 |
|
| 4609 |
|
| 4610 |
|
| 4611 |
|
| 4612 |
|
| 4613 |
|
| 4614 |
|
| 4615 |
|
| 4616 |
public long getLastRejectBackgroundTime(@OpFlags int flags) { |
| 4617 |
return getLastRejectTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 4618 |
flags); |
| 4619 |
} |
| 4620 |
|
| 4621 |
|
| 4622 |
|
| 4623 |
|
| 4624 |
|
| 4625 |
|
| 4626 |
|
| 4627 |
|
| 4628 |
private @Nullable NoteOpEvent getLastRejectEvent(@UidState int fromUidState, |
| 4629 |
@UidState int toUidState, @OpFlags int flags) { |
| 4630 |
NoteOpEvent lastAccessEvent = null; |
| 4631 |
for (AttributedOpEntry attributionEntry : mAttributedOpEntries.values()) { |
| 4632 |
NoteOpEvent lastAttributionAccessEvent = attributionEntry.getLastRejectEvent( |
| 4633 |
fromUidState, toUidState, flags); |
| 4634 |
|
| 4635 |
if (lastAccessEvent == null || (lastAttributionAccessEvent != null |
| 4636 |
&& lastAttributionAccessEvent.getNoteTime() |
| 4637 |
> lastAccessEvent.getNoteTime())) { |
| 4638 |
lastAccessEvent = lastAttributionAccessEvent; |
| 4639 |
} |
| 4640 |
} |
| 4641 |
|
| 4642 |
return lastAccessEvent; |
| 4643 |
} |
| 4644 |
|
| 4645 |
|
| 4646 |
|
| 4647 |
|
| 4648 |
|
| 4649 |
|
| 4650 |
|
| 4651 |
|
| 4652 |
|
| 4653 |
|
| 4654 |
|
| 4655 |
|
| 4656 |
|
| 4657 |
|
| 4658 |
|
| 4659 |
|
| 4660 |
|
| 4661 |
public long getLastRejectTime(@UidState int fromUidState, @UidState int toUidState, |
| 4662 |
@OpFlags int flags) { |
| 4663 |
NoteOpEvent lastEvent = getLastRejectEvent(fromUidState, toUidState, flags); |
| 4664 |
if (lastEvent == null) { |
| 4665 |
return -1; |
| 4666 |
} |
| 4667 |
|
| 4668 |
return lastEvent.getNoteTime(); |
| 4669 |
} |
| 4670 |
|
| 4671 |
|
| 4672 |
|
| 4673 |
|
| 4674 |
public boolean isRunning() { |
| 4675 |
for (AttributedOpEntry opAttributionEntry : mAttributedOpEntries.values()) { |
| 4676 |
if (opAttributionEntry.isRunning()) { |
| 4677 |
return true; |
| 4678 |
} |
| 4679 |
} |
| 4680 |
|
| 4681 |
return false; |
| 4682 |
} |
| 4683 |
|
| 4684 |
|
| 4685 |
|
| 4686 |
|
| 4687 |
@Deprecated |
| 4688 |
public long getDuration() { |
| 4689 |
return getLastDuration(OP_FLAGS_ALL); |
| 4690 |
} |
| 4691 |
|
| 4692 |
|
| 4693 |
|
| 4694 |
|
| 4695 |
|
| 4696 |
|
| 4697 |
|
| 4698 |
|
| 4699 |
|
| 4700 |
|
| 4701 |
|
| 4702 |
|
| 4703 |
|
| 4704 |
public long getLastDuration(@OpFlags int flags) { |
| 4705 |
return getLastDuration(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 4706 |
} |
| 4707 |
|
| 4708 |
|
| 4709 |
|
| 4710 |
|
| 4711 |
|
| 4712 |
|
| 4713 |
|
| 4714 |
|
| 4715 |
|
| 4716 |
|
| 4717 |
|
| 4718 |
|
| 4719 |
|
| 4720 |
public long getLastForegroundDuration(@OpFlags int flags) { |
| 4721 |
return getLastDuration(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 4722 |
flags); |
| 4723 |
} |
| 4724 |
|
| 4725 |
|
| 4726 |
|
| 4727 |
|
| 4728 |
|
| 4729 |
|
| 4730 |
|
| 4731 |
|
| 4732 |
|
| 4733 |
|
| 4734 |
|
| 4735 |
|
| 4736 |
|
| 4737 |
public long getLastBackgroundDuration(@OpFlags int flags) { |
| 4738 |
return getLastDuration(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 4739 |
flags); |
| 4740 |
} |
| 4741 |
|
| 4742 |
|
| 4743 |
|
| 4744 |
|
| 4745 |
|
| 4746 |
|
| 4747 |
|
| 4748 |
|
| 4749 |
|
| 4750 |
|
| 4751 |
|
| 4752 |
|
| 4753 |
|
| 4754 |
|
| 4755 |
|
| 4756 |
public long getLastDuration(@UidState int fromUidState, @UidState int toUidState, |
| 4757 |
@OpFlags int flags) { |
| 4758 |
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags); |
| 4759 |
if (lastEvent == null) { |
| 4760 |
return -1; |
| 4761 |
} |
| 4762 |
|
| 4763 |
return lastEvent.getDuration(); |
| 4764 |
} |
| 4765 |
|
| 4766 |
|
| 4767 |
|
| 4768 |
|
| 4769 |
@Deprecated |
| 4770 |
public int getProxyUid() { |
| 4771 |
OpEventProxyInfo proxy = getLastProxyInfo(OP_FLAGS_ALL); |
| 4772 |
if (proxy == null) { |
| 4773 |
return Process.INVALID_UID; |
| 4774 |
} |
| 4775 |
|
| 4776 |
return proxy.getUid(); |
| 4777 |
} |
| 4778 |
|
| 4779 |
|
| 4780 |
|
| 4781 |
|
| 4782 |
@Deprecated |
| 4783 |
public int getProxyUid(@UidState int uidState, @OpFlags int flags) { |
| 4784 |
OpEventProxyInfo proxy = getLastProxyInfo(uidState, uidState, flags); |
| 4785 |
if (proxy == null) { |
| 4786 |
return Process.INVALID_UID; |
| 4787 |
} |
| 4788 |
|
| 4789 |
return proxy.getUid(); |
| 4790 |
} |
| 4791 |
|
| 4792 |
|
| 4793 |
|
| 4794 |
|
| 4795 |
@Deprecated |
| 4796 |
public @Nullable String getProxyPackageName() { |
| 4797 |
OpEventProxyInfo proxy = getLastProxyInfo(OP_FLAGS_ALL); |
| 4798 |
if (proxy == null) { |
| 4799 |
return null; |
| 4800 |
} |
| 4801 |
|
| 4802 |
return proxy.getPackageName(); |
| 4803 |
} |
| 4804 |
|
| 4805 |
|
| 4806 |
|
| 4807 |
|
| 4808 |
@Deprecated |
| 4809 |
public @Nullable String getProxyPackageName(@UidState int uidState, @OpFlags int flags) { |
| 4810 |
OpEventProxyInfo proxy = getLastProxyInfo(uidState, uidState, flags); |
| 4811 |
if (proxy == null) { |
| 4812 |
return null; |
| 4813 |
} |
| 4814 |
|
| 4815 |
return proxy.getPackageName(); |
| 4816 |
} |
| 4817 |
|
| 4818 |
|
| 4819 |
|
| 4820 |
|
| 4821 |
|
| 4822 |
|
| 4823 |
|
| 4824 |
|
| 4825 |
|
| 4826 |
|
| 4827 |
|
| 4828 |
|
| 4829 |
|
| 4830 |
|
| 4831 |
public @Nullable OpEventProxyInfo getLastProxyInfo(@OpFlags int flags) { |
| 4832 |
return getLastProxyInfo(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags); |
| 4833 |
} |
| 4834 |
|
| 4835 |
|
| 4836 |
|
| 4837 |
|
| 4838 |
|
| 4839 |
|
| 4840 |
|
| 4841 |
|
| 4842 |
|
| 4843 |
|
| 4844 |
|
| 4845 |
|
| 4846 |
|
| 4847 |
|
| 4848 |
public @Nullable OpEventProxyInfo getLastForegroundProxyInfo(@OpFlags int flags) { |
| 4849 |
return getLastProxyInfo(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp), |
| 4850 |
flags); |
| 4851 |
} |
| 4852 |
|
| 4853 |
|
| 4854 |
|
| 4855 |
|
| 4856 |
|
| 4857 |
|
| 4858 |
|
| 4859 |
|
| 4860 |
|
| 4861 |
|
| 4862 |
|
| 4863 |
|
| 4864 |
|
| 4865 |
|
| 4866 |
public @Nullable OpEventProxyInfo getLastBackgroundProxyInfo(@OpFlags int flags) { |
| 4867 |
return getLastProxyInfo(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE, |
| 4868 |
flags); |
| 4869 |
} |
| 4870 |
|
| 4871 |
|
| 4872 |
|
| 4873 |
|
| 4874 |
|
| 4875 |
|
| 4876 |
|
| 4877 |
|
| 4878 |
|
| 4879 |
|
| 4880 |
|
| 4881 |
|
| 4882 |
|
| 4883 |
|
| 4884 |
|
| 4885 |
|
| 4886 |
public @Nullable OpEventProxyInfo getLastProxyInfo(@UidState int fromUidState, |
| 4887 |
@UidState int toUidState, @OpFlags int flags) { |
| 4888 |
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags); |
| 4889 |
if (lastEvent == null) { |
| 4890 |
return null; |
| 4891 |
} |
| 4892 |
|
| 4893 |
return lastEvent.getProxy(); |
| 4894 |
} |
| 4895 |
|
| 4896 |
|
| 4897 |
|
| 4898 |
|
| 4899 |
|
| 4900 |
|
| 4901 |
|
| 4902 |
|
| 4903 |
|
| 4904 |
|
| 4905 |
|
| 4906 |
|
| 4907 |
|
| 4908 |
|
| 4909 |
|
| 4910 |
|
| 4911 |
|
| 4912 |
|
| 4913 |
|
| 4914 |
|
| 4915 |
|
| 4916 |
|
| 4917 |
|
| 4918 |
|
| 4919 |
|
| 4920 |
|
| 4921 |
|
| 4922 |
@DataClass.Generated.Member |
| 4923 |
public OpEntry( |
| 4924 |
@IntRange(from = 0, to = _NUM_OP - 1) int op, |
| 4925 |
@Mode int mode, |
| 4926 |
@NonNull Map<String, AttributedOpEntry> attributedOpEntries) { |
| 4927 |
this.mOp = op; |
| 4928 |
com.android.internal.util.AnnotationValidations.validate( |
| 4929 |
IntRange.class, null, mOp, |
| 4930 |
"from", 0, |
| 4931 |
"to", _NUM_OP - 1); |
| 4932 |
this.mMode = mode; |
| 4933 |
com.android.internal.util.AnnotationValidations.validate( |
| 4934 |
Mode.class, null, mMode); |
| 4935 |
this.mAttributedOpEntries = attributedOpEntries; |
| 4936 |
com.android.internal.util.AnnotationValidations.validate( |
| 4937 |
NonNull.class, null, mAttributedOpEntries); |
| 4938 |
|
| 4939 |
|
| 4940 |
} |
| 4941 |
|
| 4942 |
|
| 4943 |
|
| 4944 |
|
| 4945 |
@DataClass.Generated.Member |
| 4946 |
public @Mode int getMode() { |
| 4947 |
return mMode; |
| 4948 |
} |
| 4949 |
|
| 4950 |
|
| 4951 |
|
| 4952 |
|
| 4953 |
|
| 4954 |
|
| 4955 |
|
| 4956 |
@DataClass.Generated.Member |
| 4957 |
public @NonNull Map<String, AttributedOpEntry> getAttributedOpEntries() { |
| 4958 |
return mAttributedOpEntries; |
| 4959 |
} |
| 4960 |
|
| 4961 |
@Override |
| 4962 |
@DataClass.Generated.Member |
| 4963 |
public void writeToParcel(Parcel dest, int flags) { |
| 4964 |
|
| 4965 |
|
| 4966 |
|
| 4967 |
dest.writeInt(mOp); |
| 4968 |
dest.writeInt(mMode); |
| 4969 |
dest.writeMap(mAttributedOpEntries); |
| 4970 |
} |
| 4971 |
|
| 4972 |
@Override |
| 4973 |
@DataClass.Generated.Member |
| 4974 |
public int describeContents() { return 0; } |
| 4975 |
|
| 4976 |
|
| 4977 |
@SuppressWarnings({"unchecked", "RedundantCast"}) |
| 4978 |
@DataClass.Generated.Member |
| 4979 |
OpEntry(@NonNull Parcel in) { |
| 4980 |
|
| 4981 |
|
| 4982 |
|
| 4983 |
int op = in.readInt(); |
| 4984 |
int mode = in.readInt(); |
| 4985 |
Map<String, AttributedOpEntry> attributions = new java.util.LinkedHashMap<>(); |
| 4986 |
in.readMap(attributions, AttributedOpEntry.class.getClassLoader()); |
| 4987 |
|
| 4988 |
this.mOp = op; |
| 4989 |
com.android.internal.util.AnnotationValidations.validate( |
| 4990 |
IntRange.class, null, mOp, |
| 4991 |
"from", 0, |
| 4992 |
"to", _NUM_OP - 1); |
| 4993 |
this.mMode = mode; |
| 4994 |
com.android.internal.util.AnnotationValidations.validate( |
| 4995 |
Mode.class, null, mMode); |
| 4996 |
this.mAttributedOpEntries = attributions; |
| 4997 |
com.android.internal.util.AnnotationValidations.validate( |
| 4998 |
NonNull.class, null, mAttributedOpEntries); |
| 4999 |
|
| 5000 |
|
| 5001 |
} |
| 5002 |
|
| 5003 |
@DataClass.Generated.Member |
| 5004 |
public static final @NonNull Parcelable.Creator<OpEntry> CREATOR |
| 5005 |
= new Parcelable.Creator<OpEntry>() { |
| 5006 |
@Override |
| 5007 |
public OpEntry[] newArray(int size) { |
| 5008 |
return new OpEntry[size]; |
| 5009 |
} |
| 5010 |
|
| 5011 |
@Override |
| 5012 |
public OpEntry createFromParcel(@NonNull Parcel in) { |
| 5013 |
return new OpEntry(in); |
| 5014 |
} |
| 5015 |
}; |
| 5016 |
|
| 5017 |
|
| 5018 |
|
| 5019 |
|
| 5020 |
|
| 5021 |
|
| 5022 |
|
| 5023 |
|
| 5024 |
|
| 5025 |
|
| 5026 |
|
| 5027 |
|
| 5028 |
|
| 5029 |
|
| 5030 |
|
| 5031 |
} |
| 5032 |
|
| 5033 |
|
| 5034 |
public interface HistoricalOpsVisitor { |
| 5035 |
void visitHistoricalOps(@NonNull HistoricalOps ops); |
| 5036 |
void visitHistoricalUidOps(@NonNull HistoricalUidOps ops); |
| 5037 |
void visitHistoricalPackageOps(@NonNull HistoricalPackageOps ops); |
| 5038 |
void visitHistoricalAttributionOps(@NonNull AttributedHistoricalOps ops); |
| 5039 |
void visitHistoricalOp(@NonNull HistoricalOp ops); |
| 5040 |
} |
| 5041 |
|
| 5042 |
|
| 5043 |
|
| 5044 |
|
| 5045 |
|
| 5046 |
|
| 5047 |
|
| 5048 |
|
| 5049 |
|
| 5050 |
@TestApi |
| 5051 |
@SystemApi |
| 5052 |
public static final int HISTORY_FLAG_AGGREGATE = 1 << 0; |
| 5053 |
|
| 5054 |
|
| 5055 |
|
| 5056 |
|
| 5057 |
|
| 5058 |
|
| 5059 |
|
| 5060 |
|
| 5061 |
|
| 5062 |
@TestApi |
| 5063 |
@SystemApi |
| 5064 |
public static final int HISTORY_FLAG_DISCRETE = 1 << 1; |
| 5065 |
|
| 5066 |
|
| 5067 |
|
| 5068 |
|
| 5069 |
|
| 5070 |
|
| 5071 |
|
| 5072 |
|
| 5073 |
|
| 5074 |
public static final int HISTORY_FLAG_GET_ATTRIBUTION_CHAINS = 1 << 2; |
| 5075 |
|
| 5076 |
|
| 5077 |
|
| 5078 |
|
| 5079 |
|
| 5080 |
|
| 5081 |
|
| 5082 |
|
| 5083 |
@TestApi |
| 5084 |
@SystemApi |
| 5085 |
public static final int HISTORY_FLAGS_ALL = HISTORY_FLAG_AGGREGATE |
| 5086 |
| HISTORY_FLAG_DISCRETE; |
| 5087 |
|
| 5088 |
|
| 5089 |
@Retention(RetentionPolicy.SOURCE) |
| 5090 |
@IntDef(flag = true, prefix = { "HISTORY_FLAG_" }, value = { |
| 5091 |
HISTORY_FLAG_AGGREGATE, |
| 5092 |
HISTORY_FLAG_DISCRETE, |
| 5093 |
HISTORY_FLAG_GET_ATTRIBUTION_CHAINS |
| 5094 |
}) |
| 5095 |
public @interface OpHistoryFlags {} |
| 5096 |
|
| 5097 |
|
| 5098 |
|
| 5099 |
|
| 5100 |
|
| 5101 |
|
| 5102 |
@Retention(RetentionPolicy.SOURCE) |
| 5103 |
@IntDef(flag = true, prefix = { "FILTER_BY_" }, value = { |
| 5104 |
FILTER_BY_UID, |
| 5105 |
FILTER_BY_PACKAGE_NAME, |
| 5106 |
FILTER_BY_ATTRIBUTION_TAG, |
| 5107 |
FILTER_BY_OP_NAMES |
| 5108 |
}) |
| 5109 |
public @interface HistoricalOpsRequestFilter {} |
| 5110 |
|
| 5111 |
|
| 5112 |
|
| 5113 |
|
| 5114 |
|
| 5115 |
|
| 5116 |
public static final int FILTER_BY_UID = 1<<0; |
| 5117 |
|
| 5118 |
|
| 5119 |
|
| 5120 |
|
| 5121 |
|
| 5122 |
|
| 5123 |
public static final int FILTER_BY_PACKAGE_NAME = 1<<1; |
| 5124 |
|
| 5125 |
|
| 5126 |
|
| 5127 |
|
| 5128 |
|
| 5129 |
|
| 5130 |
public static final int FILTER_BY_ATTRIBUTION_TAG = 1<<2; |
| 5131 |
|
| 5132 |
|
| 5133 |
|
| 5134 |
|
| 5135 |
|
| 5136 |
|
| 5137 |
public static final int FILTER_BY_OP_NAMES = 1<<3; |
| 5138 |
|
| 5139 |
|
| 5140 |
|
| 5141 |
|
| 5142 |
|
| 5143 |
|
| 5144 |
|
| 5145 |
@Immutable |
| 5146 |
@SystemApi |
| 5147 |
public static final class HistoricalOpsRequest { |
| 5148 |
private final int mUid; |
| 5149 |
private final @Nullable String mPackageName; |
| 5150 |
private final @Nullable String mAttributionTag; |
| 5151 |
private final @Nullable List<String> mOpNames; |
| 5152 |
private final @OpHistoryFlags int mHistoryFlags; |
| 5153 |
private final @HistoricalOpsRequestFilter int mFilter; |
| 5154 |
private final long mBeginTimeMillis; |
| 5155 |
private final long mEndTimeMillis; |
| 5156 |
private final @OpFlags int mFlags; |
| 5157 |
|
| 5158 |
private HistoricalOpsRequest(int uid, @Nullable String packageName, |
| 5159 |
@Nullable String attributionTag, @Nullable List<String> opNames, |
| 5160 |
@OpHistoryFlags int historyFlags, @HistoricalOpsRequestFilter int filter, |
| 5161 |
long beginTimeMillis, long endTimeMillis, @OpFlags int flags) { |
| 5162 |
mUid = uid; |
| 5163 |
mPackageName = packageName; |
| 5164 |
mAttributionTag = attributionTag; |
| 5165 |
mOpNames = opNames; |
| 5166 |
mHistoryFlags = historyFlags; |
| 5167 |
mFilter = filter; |
| 5168 |
mBeginTimeMillis = beginTimeMillis; |
| 5169 |
mEndTimeMillis = endTimeMillis; |
| 5170 |
mFlags = flags; |
| 5171 |
} |
| 5172 |
|
| 5173 |
|
| 5174 |
|
| 5175 |
|
| 5176 |
|
| 5177 |
|
| 5178 |
@SystemApi |
| 5179 |
public static final class Builder { |
| 5180 |
private int mUid = Process.INVALID_UID; |
| 5181 |
private @Nullable String mPackageName; |
| 5182 |
private @Nullable String mAttributionTag; |
| 5183 |
private @Nullable List<String> mOpNames; |
| 5184 |
private @OpHistoryFlags int mHistoryFlags; |
| 5185 |
private @HistoricalOpsRequestFilter int mFilter; |
| 5186 |
private final long mBeginTimeMillis; |
| 5187 |
private final long mEndTimeMillis; |
| 5188 |
private @OpFlags int mFlags = OP_FLAGS_ALL; |
| 5189 |
|
| 5190 |
|
| 5191 |
|
| 5192 |
|
| 5193 |
|
| 5194 |
|
| 5195 |
|
| 5196 |
|
| 5197 |
|
| 5198 |
|
| 5199 |
|
| 5200 |
|
| 5201 |
public Builder(long beginTimeMillis, long endTimeMillis) { |
| 5202 |
Preconditions.checkArgument(beginTimeMillis >= 0 && beginTimeMillis < endTimeMillis, |
| 5203 |
"beginTimeMillis must be non negative and lesser than endTimeMillis"); |
| 5204 |
mBeginTimeMillis = beginTimeMillis; |
| 5205 |
mEndTimeMillis = endTimeMillis; |
| 5206 |
mHistoryFlags = HISTORY_FLAG_AGGREGATE; |
| 5207 |
} |
| 5208 |
|
| 5209 |
|
| 5210 |
|
| 5211 |
|
| 5212 |
|
| 5213 |
|
| 5214 |
|
| 5215 |
public @NonNull Builder setUid(int uid) { |
| 5216 |
Preconditions.checkArgument(uid == Process.INVALID_UID || uid >= 0, |
| 5217 |
"uid must be " + Process.INVALID_UID + " or non negative"); |
| 5218 |
mUid = uid; |
| 5219 |
|
| 5220 |
if (uid == Process.INVALID_UID) { |
| 5221 |
mFilter &= ~FILTER_BY_UID; |
| 5222 |
} else { |
| 5223 |
mFilter |= FILTER_BY_UID; |
| 5224 |
} |
| 5225 |
|
| 5226 |
return this; |
| 5227 |
} |
| 5228 |
|
| 5229 |
|
| 5230 |
|
| 5231 |
|
| 5232 |
|
| 5233 |
|
| 5234 |
|
| 5235 |
public @NonNull Builder setPackageName(@Nullable String packageName) { |
| 5236 |
mPackageName = packageName; |
| 5237 |
|
| 5238 |
if (packageName == null) { |
| 5239 |
mFilter &= ~FILTER_BY_PACKAGE_NAME; |
| 5240 |
} else { |
| 5241 |
mFilter |= FILTER_BY_PACKAGE_NAME; |
| 5242 |
} |
| 5243 |
|
| 5244 |
return this; |
| 5245 |
} |
| 5246 |
|
| 5247 |
|
| 5248 |
|
| 5249 |
|
| 5250 |
|
| 5251 |
|
| 5252 |
|
| 5253 |
public @NonNull Builder setAttributionTag(@Nullable String attributionTag) { |
| 5254 |
mAttributionTag = attributionTag; |
| 5255 |
mFilter |= FILTER_BY_ATTRIBUTION_TAG; |
| 5256 |
|
| 5257 |
return this; |
| 5258 |
} |
| 5259 |
|
| 5260 |
|
| 5261 |
|
| 5262 |
|
| 5263 |
|
| 5264 |
|
| 5265 |
|
| 5266 |
public @NonNull Builder setOpNames(@Nullable List<String> opNames) { |
| 5267 |
if (opNames != null) { |
| 5268 |
final int opCount = opNames.size(); |
| 5269 |
for (int i = 0; i < opCount; i++) { |
| 5270 |
Preconditions.checkArgument(AppOpsManager.strOpToOp( |
| 5271 |
opNames.get(i)) != AppOpsManager.OP_NONE); |
| 5272 |
} |
| 5273 |
} |
| 5274 |
mOpNames = opNames; |
| 5275 |
|
| 5276 |
if (mOpNames == null) { |
| 5277 |
mFilter &= ~FILTER_BY_OP_NAMES; |
| 5278 |
} else { |
| 5279 |
mFilter |= FILTER_BY_OP_NAMES; |
| 5280 |
} |
| 5281 |
|
| 5282 |
return this; |
| 5283 |
} |
| 5284 |
|
| 5285 |
|
| 5286 |
|
| 5287 |
|
| 5288 |
|
| 5289 |
|
| 5290 |
|
| 5291 |
|
| 5292 |
|
| 5293 |
|
| 5294 |
|
| 5295 |
|
| 5296 |
public @NonNull Builder setFlags(@OpFlags int flags) { |
| 5297 |
Preconditions.checkFlagsArgument(flags, OP_FLAGS_ALL); |
| 5298 |
mFlags = flags; |
| 5299 |
return this; |
| 5300 |
} |
| 5301 |
|
| 5302 |
|
| 5303 |
|
| 5304 |
|
| 5305 |
|
| 5306 |
|
| 5307 |
|
| 5308 |
|
| 5309 |
|
| 5310 |
public @NonNull Builder setHistoryFlags(@OpHistoryFlags int flags) { |
| 5311 |
Preconditions.checkFlagsArgument(flags, |
| 5312 |
HISTORY_FLAGS_ALL | HISTORY_FLAG_GET_ATTRIBUTION_CHAINS); |
| 5313 |
mHistoryFlags = flags; |
| 5314 |
return this; |
| 5315 |
} |
| 5316 |
|
| 5317 |
|
| 5318 |
|
| 5319 |
|
| 5320 |
public @NonNull HistoricalOpsRequest build() { |
| 5321 |
return new HistoricalOpsRequest(mUid, mPackageName, mAttributionTag, mOpNames, |
| 5322 |
mHistoryFlags, mFilter, mBeginTimeMillis, mEndTimeMillis, mFlags); |
| 5323 |
} |
| 5324 |
} |
| 5325 |
} |
| 5326 |
|
| 5327 |
|
| 5328 |
|
| 5329 |
|
| 5330 |
|
| 5331 |
|
| 5332 |
@SystemApi |
| 5333 |
public static final class HistoricalOps implements Parcelable { |
| 5334 |
private long mBeginTimeMillis; |
| 5335 |
private long mEndTimeMillis; |
| 5336 |
private @Nullable SparseArray<HistoricalUidOps> mHistoricalUidOps; |
| 5337 |
|
| 5338 |
|
| 5339 |
@TestApi |
| 5340 |
public HistoricalOps(long beginTimeMillis, long endTimeMillis) { |
| 5341 |
Preconditions.checkState(beginTimeMillis <= endTimeMillis); |
| 5342 |
mBeginTimeMillis = beginTimeMillis; |
| 5343 |
mEndTimeMillis = endTimeMillis; |
| 5344 |
} |
| 5345 |
|
| 5346 |
|
| 5347 |
public HistoricalOps(@NonNull HistoricalOps other) { |
| 5348 |
mBeginTimeMillis = other.mBeginTimeMillis; |
| 5349 |
mEndTimeMillis = other.mEndTimeMillis; |
| 5350 |
Preconditions.checkState(mBeginTimeMillis <= mEndTimeMillis); |
| 5351 |
if (other.mHistoricalUidOps != null) { |
| 5352 |
final int opCount = other.getUidCount(); |
| 5353 |
for (int i = 0; i < opCount; i++) { |
| 5354 |
final HistoricalUidOps origOps = other.getUidOpsAt(i); |
| 5355 |
final HistoricalUidOps clonedOps = new HistoricalUidOps(origOps); |
| 5356 |
if (mHistoricalUidOps == null) { |
| 5357 |
mHistoricalUidOps = new SparseArray<>(opCount); |
| 5358 |
} |
| 5359 |
mHistoricalUidOps.put(clonedOps.getUid(), clonedOps); |
| 5360 |
} |
| 5361 |
} |
| 5362 |
} |
| 5363 |
|
| 5364 |
private HistoricalOps(Parcel parcel) { |
| 5365 |
mBeginTimeMillis = parcel.readLong(); |
| 5366 |
mEndTimeMillis = parcel.readLong(); |
| 5367 |
final int[] uids = parcel.createIntArray(); |
| 5368 |
if (!ArrayUtils.isEmpty(uids)) { |
| 5369 |
final ParceledListSlice<HistoricalUidOps> listSlice = parcel.readParcelable( |
| 5370 |
HistoricalOps.class.getClassLoader(), android.content.pm.ParceledListSlice.class); |
| 5371 |
final List<HistoricalUidOps> uidOps = (listSlice != null) |
| 5372 |
? listSlice.getList() : null; |
| 5373 |
if (uidOps == null) { |
| 5374 |
return; |
| 5375 |
} |
| 5376 |
for (int i = 0; i < uids.length; i++) { |
| 5377 |
if (mHistoricalUidOps == null) { |
| 5378 |
mHistoricalUidOps = new SparseArray<>(); |
| 5379 |
} |
| 5380 |
mHistoricalUidOps.put(uids[i], uidOps.get(i)); |
| 5381 |
} |
| 5382 |
} |
| 5383 |
} |
| 5384 |
|
| 5385 |
|
| 5386 |
|
| 5387 |
|
| 5388 |
|
| 5389 |
|
| 5390 |
|
| 5391 |
|
| 5392 |
public @NonNull HistoricalOps spliceFromBeginning(double splicePoint) { |
| 5393 |
return splice(splicePoint, true); |
| 5394 |
} |
| 5395 |
|
| 5396 |
|
| 5397 |
|
| 5398 |
|
| 5399 |
|
| 5400 |
|
| 5401 |
|
| 5402 |
|
| 5403 |
public @NonNull HistoricalOps spliceFromEnd(double fractionToRemove) { |
| 5404 |
return splice(fractionToRemove, false); |
| 5405 |
} |
| 5406 |
|
| 5407 |
|
| 5408 |
|
| 5409 |
|
| 5410 |
|
| 5411 |
|
| 5412 |
|
| 5413 |
|
| 5414 |
|
| 5415 |
|
| 5416 |
|
| 5417 |
private @Nullable HistoricalOps splice(double fractionToRemove, boolean beginning) { |
| 5418 |
final long spliceBeginTimeMills; |
| 5419 |
final long spliceEndTimeMills; |
| 5420 |
if (beginning) { |
| 5421 |
spliceBeginTimeMills = mBeginTimeMillis; |
| 5422 |
spliceEndTimeMills = (long) (mBeginTimeMillis |
| 5423 |
+ getDurationMillis() * fractionToRemove); |
| 5424 |
mBeginTimeMillis = spliceEndTimeMills; |
| 5425 |
} else { |
| 5426 |
spliceBeginTimeMills = (long) (mEndTimeMillis |
| 5427 |
- getDurationMillis() * fractionToRemove); |
| 5428 |
spliceEndTimeMills = mEndTimeMillis; |
| 5429 |
mEndTimeMillis = spliceBeginTimeMills; |
| 5430 |
} |
| 5431 |
|
| 5432 |
HistoricalOps splice = null; |
| 5433 |
final int uidCount = getUidCount(); |
| 5434 |
for (int i = 0; i < uidCount; i++) { |
| 5435 |
final HistoricalUidOps origOps = getUidOpsAt(i); |
| 5436 |
final HistoricalUidOps spliceOps = origOps.splice(fractionToRemove); |
| 5437 |
if (spliceOps != null) { |
| 5438 |
if (splice == null) { |
| 5439 |
splice = new HistoricalOps(spliceBeginTimeMills, spliceEndTimeMills); |
| 5440 |
} |
| 5441 |
if (splice.mHistoricalUidOps == null) { |
| 5442 |
splice.mHistoricalUidOps = new SparseArray<>(); |
| 5443 |
} |
| 5444 |
splice.mHistoricalUidOps.put(spliceOps.getUid(), spliceOps); |
| 5445 |
} |
| 5446 |
} |
| 5447 |
return splice; |
| 5448 |
} |
| 5449 |
|
| 5450 |
|
| 5451 |
|
| 5452 |
|
| 5453 |
|
| 5454 |
|
| 5455 |
|
| 5456 |
|
| 5457 |
public void merge(@NonNull HistoricalOps other) { |
| 5458 |
mBeginTimeMillis = Math.min(mBeginTimeMillis, other.mBeginTimeMillis); |
| 5459 |
mEndTimeMillis = Math.max(mEndTimeMillis, other.mEndTimeMillis); |
| 5460 |
final int uidCount = other.getUidCount(); |
| 5461 |
for (int i = 0; i < uidCount; i++) { |
| 5462 |
final HistoricalUidOps otherUidOps = other.getUidOpsAt(i); |
| 5463 |
final HistoricalUidOps thisUidOps = getUidOps(otherUidOps.getUid()); |
| 5464 |
if (thisUidOps != null) { |
| 5465 |
thisUidOps.merge(otherUidOps); |
| 5466 |
} else { |
| 5467 |
if (mHistoricalUidOps == null) { |
| 5468 |
mHistoricalUidOps = new SparseArray<>(); |
| 5469 |
} |
| 5470 |
mHistoricalUidOps.put(otherUidOps.getUid(), otherUidOps); |
| 5471 |
} |
| 5472 |
} |
| 5473 |
} |
| 5474 |
|
| 5475 |
|
| 5476 |
|
| 5477 |
|
| 5478 |
|
| 5479 |
|
| 5480 |
|
| 5481 |
|
| 5482 |
|
| 5483 |
|
| 5484 |
|
| 5485 |
|
| 5486 |
|
| 5487 |
|
| 5488 |
public void filter(int uid, @Nullable String packageName, @Nullable String attributionTag, |
| 5489 |
@Nullable String[] opNames, @OpHistoryFlags int historyFilter, |
| 5490 |
@HistoricalOpsRequestFilter int filter, |
| 5491 |
long beginTimeMillis, long endTimeMillis) { |
| 5492 |
final long durationMillis = getDurationMillis(); |
| 5493 |
mBeginTimeMillis = Math.max(mBeginTimeMillis, beginTimeMillis); |
| 5494 |
mEndTimeMillis = Math.min(mEndTimeMillis, endTimeMillis); |
| 5495 |
final double scaleFactor = Math.min((double) (endTimeMillis - beginTimeMillis) |
| 5496 |
/ (double) durationMillis, 1); |
| 5497 |
final int uidCount = getUidCount(); |
| 5498 |
for (int i = uidCount - 1; i >= 0; i--) { |
| 5499 |
final HistoricalUidOps uidOp = mHistoricalUidOps.valueAt(i); |
| 5500 |
if ((filter & FILTER_BY_UID) != 0 && uid != uidOp.getUid()) { |
| 5501 |
mHistoricalUidOps.removeAt(i); |
| 5502 |
} else { |
| 5503 |
uidOp.filter(packageName, attributionTag, opNames, filter, historyFilter, |
| 5504 |
scaleFactor, mBeginTimeMillis, mEndTimeMillis); |
| 5505 |
if (uidOp.getPackageCount() == 0) { |
| 5506 |
mHistoricalUidOps.removeAt(i); |
| 5507 |
} |
| 5508 |
} |
| 5509 |
} |
| 5510 |
} |
| 5511 |
|
| 5512 |
|
| 5513 |
public boolean isEmpty() { |
| 5514 |
if (getBeginTimeMillis() >= getEndTimeMillis()) { |
| 5515 |
return true; |
| 5516 |
} |
| 5517 |
final int uidCount = getUidCount(); |
| 5518 |
for (int i = uidCount - 1; i >= 0; i--) { |
| 5519 |
final HistoricalUidOps uidOp = mHistoricalUidOps.valueAt(i); |
| 5520 |
if (!uidOp.isEmpty()) { |
| 5521 |
return false; |
| 5522 |
} |
| 5523 |
} |
| 5524 |
return true; |
| 5525 |
} |
| 5526 |
|
| 5527 |
|
| 5528 |
public long getDurationMillis() { |
| 5529 |
return mEndTimeMillis - mBeginTimeMillis; |
| 5530 |
} |
| 5531 |
|
| 5532 |
|
| 5533 |
@TestApi |
| 5534 |
public void increaseAccessCount(int opCode, int uid, @NonNull String packageName, |
| 5535 |
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
| 5536 |
long increment) { |
| 5537 |
getOrCreateHistoricalUidOps(uid).increaseAccessCount(opCode, |
| 5538 |
packageName, attributionTag, uidState, flags, increment); |
| 5539 |
} |
| 5540 |
|
| 5541 |
|
| 5542 |
@TestApi |
| 5543 |
public void increaseRejectCount(int opCode, int uid, @NonNull String packageName, |
| 5544 |
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
| 5545 |
long increment) { |
| 5546 |
getOrCreateHistoricalUidOps(uid).increaseRejectCount(opCode, |
| 5547 |
packageName, attributionTag, uidState, flags, increment); |
| 5548 |
} |
| 5549 |
|
| 5550 |
|
| 5551 |
@TestApi |
| 5552 |
public void increaseAccessDuration(int opCode, int uid, @NonNull String packageName, |
| 5553 |
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
| 5554 |
long increment) { |
| 5555 |
getOrCreateHistoricalUidOps(uid).increaseAccessDuration(opCode, |
| 5556 |
packageName, attributionTag, uidState, flags, increment); |
| 5557 |
} |
| 5558 |
|
| 5559 |
|
| 5560 |
@TestApi |
| 5561 |
public void addDiscreteAccess(int opCode, int uid, @NonNull String packageName, |
| 5562 |
@Nullable String attributionTag, @UidState int uidState, @OpFlags int opFlag, |
| 5563 |
long discreteAccessTime, long discreteAccessDuration) { |
| 5564 |
getOrCreateHistoricalUidOps(uid).addDiscreteAccess(opCode, packageName, attributionTag, |
| 5565 |
uidState, opFlag, discreteAccessTime, discreteAccessDuration, null); |
| 5566 |
} |
| 5567 |
|
| 5568 |
|
| 5569 |
public void addDiscreteAccess(int opCode, int uid, @NonNull String packageName, |
| 5570 |
@Nullable String attributionTag, @UidState int uidState, @OpFlags int opFlag, |
| 5571 |
long discreteAccessTime, long discreteAccessDuration, |
| 5572 |
@Nullable OpEventProxyInfo proxy) { |
| 5573 |
getOrCreateHistoricalUidOps(uid).addDiscreteAccess(opCode, packageName, attributionTag, |
| 5574 |
uidState, opFlag, discreteAccessTime, discreteAccessDuration, proxy); |
| 5575 |
} |
| 5576 |
|
| 5577 |
|
| 5578 |
|
| 5579 |
@TestApi |
| 5580 |
public void offsetBeginAndEndTime(long offsetMillis) { |
| 5581 |
mBeginTimeMillis += offsetMillis; |
| 5582 |
mEndTimeMillis += offsetMillis; |
| 5583 |
} |
| 5584 |
|
| 5585 |
|
| 5586 |
public void setBeginAndEndTime(long beginTimeMillis, long endTimeMillis) { |
| 5587 |
mBeginTimeMillis = beginTimeMillis; |
| 5588 |
mEndTimeMillis = endTimeMillis; |
| 5589 |
} |
| 5590 |
|
| 5591 |
|
| 5592 |
public void setBeginTime(long beginTimeMillis) { |
| 5593 |
mBeginTimeMillis = beginTimeMillis; |
| 5594 |
} |
| 5595 |
|
| 5596 |
|
| 5597 |
public void setEndTime(long endTimeMillis) { |
| 5598 |
mEndTimeMillis = endTimeMillis; |
| 5599 |
} |
| 5600 |
|
| 5601 |
|
| 5602 |
|
| 5603 |
|
| 5604 |
|
| 5605 |
public long getBeginTimeMillis() { |
| 5606 |
return mBeginTimeMillis; |
| 5607 |
} |
| 5608 |
|
| 5609 |
|
| 5610 |
|
| 5611 |
|
| 5612 |
|
| 5613 |
public long getEndTimeMillis() { |
| 5614 |
return mEndTimeMillis; |
| 5615 |
} |
| 5616 |
|
| 5617 |
|
| 5618 |
|
| 5619 |
|
| 5620 |
|
| 5621 |
|
| 5622 |
|
| 5623 |
|
| 5624 |
public @IntRange(from = 0) int getUidCount() { |
| 5625 |
if (mHistoricalUidOps == null) { |
| 5626 |
return 0; |
| 5627 |
} |
| 5628 |
return mHistoricalUidOps.size(); |
| 5629 |
} |
| 5630 |
|
| 5631 |
|
| 5632 |
|
| 5633 |
|
| 5634 |
|
| 5635 |
|
| 5636 |
|
| 5637 |
|
| 5638 |
|
| 5639 |
|
| 5640 |
public @NonNull HistoricalUidOps getUidOpsAt(@IntRange(from = 0) int index) { |
| 5641 |
if (mHistoricalUidOps == null) { |
| 5642 |
throw new IndexOutOfBoundsException(); |
| 5643 |
} |
| 5644 |
return mHistoricalUidOps.valueAt(index); |
| 5645 |
} |
| 5646 |
|
| 5647 |
|
| 5648 |
|
| 5649 |
|
| 5650 |
|
| 5651 |
|
| 5652 |
|
| 5653 |
|
| 5654 |
public @Nullable HistoricalUidOps getUidOps(int uid) { |
| 5655 |
if (mHistoricalUidOps == null) { |
| 5656 |
return null; |
| 5657 |
} |
| 5658 |
return mHistoricalUidOps.get(uid); |
| 5659 |
} |
| 5660 |
|
| 5661 |
|
| 5662 |
public void clearHistory(int uid, @NonNull String packageName) { |
| 5663 |
HistoricalUidOps historicalUidOps = getOrCreateHistoricalUidOps(uid); |
| 5664 |
historicalUidOps.clearHistory(packageName); |
| 5665 |
if (historicalUidOps.isEmpty()) { |
| 5666 |
mHistoricalUidOps.remove(uid); |
| 5667 |
} |
| 5668 |
} |
| 5669 |
|
| 5670 |
@Override |
| 5671 |
public int describeContents() { |
| 5672 |
return 0; |
| 5673 |
} |
| 5674 |
|
| 5675 |
@Override |
| 5676 |
public void writeToParcel(Parcel parcel, int flags) { |
| 5677 |
parcel.writeLong(mBeginTimeMillis); |
| 5678 |
parcel.writeLong(mEndTimeMillis); |
| 5679 |
if (mHistoricalUidOps != null) { |
| 5680 |
final int uidCount = mHistoricalUidOps.size(); |
| 5681 |
parcel.writeInt(uidCount); |
| 5682 |
for (int i = 0; i < uidCount; i++) { |
| 5683 |
parcel.writeInt(mHistoricalUidOps.keyAt(i)); |
| 5684 |
} |
| 5685 |
final List<HistoricalUidOps> opsList = new ArrayList<>(uidCount); |
| 5686 |
for (int i = 0; i < uidCount; i++) { |
| 5687 |
opsList.add(mHistoricalUidOps.valueAt(i)); |
| 5688 |
} |
| 5689 |
parcel.writeParcelable(new ParceledListSlice<>(opsList), flags); |
| 5690 |
} else { |
| 5691 |
parcel.writeInt(-1); |
| 5692 |
} |
| 5693 |
} |
| 5694 |
|
| 5695 |
|
| 5696 |
|
| 5697 |
|
| 5698 |
|
| 5699 |
|
| 5700 |
|
| 5701 |
|
| 5702 |
public void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 5703 |
visitor.visitHistoricalOps(this); |
| 5704 |
final int uidCount = getUidCount(); |
| 5705 |
for (int i = 0; i < uidCount; i++) { |
| 5706 |
getUidOpsAt(i).accept(visitor); |
| 5707 |
} |
| 5708 |
} |
| 5709 |
|
| 5710 |
private @NonNull HistoricalUidOps getOrCreateHistoricalUidOps(int uid) { |
| 5711 |
if (mHistoricalUidOps == null) { |
| 5712 |
mHistoricalUidOps = new SparseArray<>(); |
| 5713 |
} |
| 5714 |
HistoricalUidOps historicalUidOp = mHistoricalUidOps.get(uid); |
| 5715 |
if (historicalUidOp == null) { |
| 5716 |
historicalUidOp = new HistoricalUidOps(uid); |
| 5717 |
mHistoricalUidOps.put(uid, historicalUidOp); |
| 5718 |
} |
| 5719 |
return historicalUidOp; |
| 5720 |
} |
| 5721 |
|
| 5722 |
|
| 5723 |
|
| 5724 |
|
| 5725 |
|
| 5726 |
|
| 5727 |
public static double round(double value) { |
| 5728 |
return Math.floor(value + 0.5); |
| 5729 |
} |
| 5730 |
|
| 5731 |
@Override |
| 5732 |
public boolean equals(@Nullable Object obj) { |
| 5733 |
if (this == obj) { |
| 5734 |
return true; |
| 5735 |
} |
| 5736 |
if (obj == null || getClass() != obj.getClass()) { |
| 5737 |
return false; |
| 5738 |
} |
| 5739 |
final HistoricalOps other = (HistoricalOps) obj; |
| 5740 |
if (mBeginTimeMillis != other.mBeginTimeMillis) { |
| 5741 |
return false; |
| 5742 |
} |
| 5743 |
if (mEndTimeMillis != other.mEndTimeMillis) { |
| 5744 |
return false; |
| 5745 |
} |
| 5746 |
if (mHistoricalUidOps == null) { |
| 5747 |
if (other.mHistoricalUidOps != null) { |
| 5748 |
return false; |
| 5749 |
} |
| 5750 |
} else if (!mHistoricalUidOps.equals(other.mHistoricalUidOps)) { |
| 5751 |
return false; |
| 5752 |
} |
| 5753 |
return true; |
| 5754 |
} |
| 5755 |
|
| 5756 |
@Override |
| 5757 |
public int hashCode() { |
| 5758 |
int result = (int) (mBeginTimeMillis ^ (mBeginTimeMillis >>> 32)); |
| 5759 |
result = 31 * result + mHistoricalUidOps.hashCode(); |
| 5760 |
return result; |
| 5761 |
} |
| 5762 |
|
| 5763 |
@NonNull |
| 5764 |
@Override |
| 5765 |
public String toString() { |
| 5766 |
return getClass().getSimpleName() + "[from:" |
| 5767 |
+ mBeginTimeMillis + " to:" + mEndTimeMillis + "]"; |
| 5768 |
} |
| 5769 |
|
| 5770 |
public static final @android.annotation.NonNull Creator<HistoricalOps> CREATOR = new Creator<HistoricalOps>() { |
| 5771 |
@Override |
| 5772 |
public @NonNull HistoricalOps createFromParcel(@NonNull Parcel parcel) { |
| 5773 |
return new HistoricalOps(parcel); |
| 5774 |
} |
| 5775 |
|
| 5776 |
@Override |
| 5777 |
public @NonNull HistoricalOps[] newArray(int size) { |
| 5778 |
return new HistoricalOps[size]; |
| 5779 |
} |
| 5780 |
}; |
| 5781 |
} |
| 5782 |
|
| 5783 |
|
| 5784 |
|
| 5785 |
|
| 5786 |
|
| 5787 |
|
| 5788 |
@SystemApi |
| 5789 |
public static final class HistoricalUidOps implements Parcelable { |
| 5790 |
private final int mUid; |
| 5791 |
private @Nullable ArrayMap<String, HistoricalPackageOps> mHistoricalPackageOps; |
| 5792 |
|
| 5793 |
|
| 5794 |
public HistoricalUidOps(int uid) { |
| 5795 |
mUid = uid; |
| 5796 |
} |
| 5797 |
|
| 5798 |
private HistoricalUidOps(@NonNull HistoricalUidOps other) { |
| 5799 |
mUid = other.mUid; |
| 5800 |
final int opCount = other.getPackageCount(); |
| 5801 |
for (int i = 0; i < opCount; i++) { |
| 5802 |
final HistoricalPackageOps origOps = other.getPackageOpsAt(i); |
| 5803 |
final HistoricalPackageOps cloneOps = new HistoricalPackageOps(origOps); |
| 5804 |
if (mHistoricalPackageOps == null) { |
| 5805 |
mHistoricalPackageOps = new ArrayMap<>(opCount); |
| 5806 |
} |
| 5807 |
mHistoricalPackageOps.put(cloneOps.getPackageName(), cloneOps); |
| 5808 |
} |
| 5809 |
} |
| 5810 |
|
| 5811 |
private HistoricalUidOps(@NonNull Parcel parcel) { |
| 5812 |
|
| 5813 |
mUid = parcel.readInt(); |
| 5814 |
mHistoricalPackageOps = parcel.createTypedArrayMap(HistoricalPackageOps.CREATOR); |
| 5815 |
} |
| 5816 |
|
| 5817 |
private @Nullable HistoricalUidOps splice(double fractionToRemove) { |
| 5818 |
HistoricalUidOps splice = null; |
| 5819 |
final int packageCount = getPackageCount(); |
| 5820 |
for (int i = 0; i < packageCount; i++) { |
| 5821 |
final HistoricalPackageOps origOps = getPackageOpsAt(i); |
| 5822 |
final HistoricalPackageOps spliceOps = origOps.splice(fractionToRemove); |
| 5823 |
if (spliceOps != null) { |
| 5824 |
if (splice == null) { |
| 5825 |
splice = new HistoricalUidOps(mUid); |
| 5826 |
} |
| 5827 |
if (splice.mHistoricalPackageOps == null) { |
| 5828 |
splice.mHistoricalPackageOps = new ArrayMap<>(); |
| 5829 |
} |
| 5830 |
splice.mHistoricalPackageOps.put(spliceOps.getPackageName(), spliceOps); |
| 5831 |
} |
| 5832 |
} |
| 5833 |
return splice; |
| 5834 |
} |
| 5835 |
|
| 5836 |
private void merge(@NonNull HistoricalUidOps other) { |
| 5837 |
final int packageCount = other.getPackageCount(); |
| 5838 |
for (int i = 0; i < packageCount; i++) { |
| 5839 |
final HistoricalPackageOps otherPackageOps = other.getPackageOpsAt(i); |
| 5840 |
final HistoricalPackageOps thisPackageOps = getPackageOps( |
| 5841 |
otherPackageOps.getPackageName()); |
| 5842 |
if (thisPackageOps != null) { |
| 5843 |
thisPackageOps.merge(otherPackageOps); |
| 5844 |
} else { |
| 5845 |
if (mHistoricalPackageOps == null) { |
| 5846 |
mHistoricalPackageOps = new ArrayMap<>(); |
| 5847 |
} |
| 5848 |
mHistoricalPackageOps.put(otherPackageOps.getPackageName(), otherPackageOps); |
| 5849 |
} |
| 5850 |
} |
| 5851 |
} |
| 5852 |
|
| 5853 |
private void filter(@Nullable String packageName, @Nullable String attributionTag, |
| 5854 |
@Nullable String[] opNames, @HistoricalOpsRequestFilter int filter, |
| 5855 |
@OpHistoryFlags int historyFilter, double fractionToRemove, long beginTimeMillis, |
| 5856 |
long endTimeMillis) { |
| 5857 |
final int packageCount = getPackageCount(); |
| 5858 |
for (int i = packageCount - 1; i >= 0; i--) { |
| 5859 |
final HistoricalPackageOps packageOps = getPackageOpsAt(i); |
| 5860 |
if ((filter & FILTER_BY_PACKAGE_NAME) != 0 && !packageName.equals( |
| 5861 |
packageOps.getPackageName())) { |
| 5862 |
mHistoricalPackageOps.removeAt(i); |
| 5863 |
} else { |
| 5864 |
packageOps.filter(attributionTag, opNames, filter, historyFilter, |
| 5865 |
fractionToRemove, beginTimeMillis, endTimeMillis); |
| 5866 |
if (packageOps.getAttributedOpsCount() == 0) { |
| 5867 |
mHistoricalPackageOps.removeAt(i); |
| 5868 |
} |
| 5869 |
} |
| 5870 |
} |
| 5871 |
} |
| 5872 |
|
| 5873 |
private boolean isEmpty() { |
| 5874 |
final int packageCount = getPackageCount(); |
| 5875 |
for (int i = packageCount - 1; i >= 0; i--) { |
| 5876 |
final HistoricalPackageOps packageOps = mHistoricalPackageOps.valueAt(i); |
| 5877 |
if (!packageOps.isEmpty()) { |
| 5878 |
return false; |
| 5879 |
} |
| 5880 |
} |
| 5881 |
return true; |
| 5882 |
} |
| 5883 |
|
| 5884 |
private void increaseAccessCount(int opCode, @NonNull String packageName, |
| 5885 |
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
| 5886 |
long increment) { |
| 5887 |
getOrCreateHistoricalPackageOps(packageName).increaseAccessCount( |
| 5888 |
opCode, attributionTag, uidState, flags, increment); |
| 5889 |
} |
| 5890 |
|
| 5891 |
private void increaseRejectCount(int opCode, @NonNull String packageName, |
| 5892 |
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
| 5893 |
long increment) { |
| 5894 |
getOrCreateHistoricalPackageOps(packageName).increaseRejectCount( |
| 5895 |
opCode, attributionTag, uidState, flags, increment); |
| 5896 |
} |
| 5897 |
|
| 5898 |
private void increaseAccessDuration(int opCode, @NonNull String packageName, |
| 5899 |
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags, |
| 5900 |
long increment) { |
| 5901 |
getOrCreateHistoricalPackageOps(packageName).increaseAccessDuration( |
| 5902 |
opCode, attributionTag, uidState, flags, increment); |
| 5903 |
} |
| 5904 |
|
| 5905 |
private void addDiscreteAccess(int opCode, @NonNull String packageName, |
| 5906 |
@Nullable String attributionTag, @UidState int uidState, |
| 5907 |
@OpFlags int flag, long discreteAccessTime, long discreteAccessDuration, |
| 5908 |
@Nullable OpEventProxyInfo proxy) { |
| 5909 |
getOrCreateHistoricalPackageOps(packageName).addDiscreteAccess(opCode, attributionTag, |
| 5910 |
uidState, flag, discreteAccessTime, discreteAccessDuration, proxy); |
| 5911 |
}; |
| 5912 |
|
| 5913 |
|
| 5914 |
|
| 5915 |
|
| 5916 |
public int getUid() { |
| 5917 |
return mUid; |
| 5918 |
} |
| 5919 |
|
| 5920 |
|
| 5921 |
|
| 5922 |
|
| 5923 |
|
| 5924 |
|
| 5925 |
|
| 5926 |
|
| 5927 |
public @IntRange(from = 0) int getPackageCount() { |
| 5928 |
if (mHistoricalPackageOps == null) { |
| 5929 |
return 0; |
| 5930 |
} |
| 5931 |
return mHistoricalPackageOps.size(); |
| 5932 |
} |
| 5933 |
|
| 5934 |
|
| 5935 |
|
| 5936 |
|
| 5937 |
|
| 5938 |
|
| 5939 |
|
| 5940 |
|
| 5941 |
|
| 5942 |
|
| 5943 |
public @NonNull HistoricalPackageOps getPackageOpsAt(@IntRange(from = 0) int index) { |
| 5944 |
if (mHistoricalPackageOps == null) { |
| 5945 |
throw new IndexOutOfBoundsException(); |
| 5946 |
} |
| 5947 |
return mHistoricalPackageOps.valueAt(index); |
| 5948 |
} |
| 5949 |
|
| 5950 |
|
| 5951 |
|
| 5952 |
|
| 5953 |
|
| 5954 |
|
| 5955 |
|
| 5956 |
|
| 5957 |
public @Nullable HistoricalPackageOps getPackageOps(@NonNull String packageName) { |
| 5958 |
if (mHistoricalPackageOps == null) { |
| 5959 |
return null; |
| 5960 |
} |
| 5961 |
return mHistoricalPackageOps.get(packageName); |
| 5962 |
} |
| 5963 |
|
| 5964 |
private void clearHistory(@NonNull String packageName) { |
| 5965 |
if (mHistoricalPackageOps != null) { |
| 5966 |
mHistoricalPackageOps.remove(packageName); |
| 5967 |
} |
| 5968 |
} |
| 5969 |
|
| 5970 |
@Override |
| 5971 |
public int describeContents() { |
| 5972 |
return 0; |
| 5973 |
} |
| 5974 |
|
| 5975 |
@Override |
| 5976 |
public void writeToParcel(Parcel parcel, int flags) { |
| 5977 |
parcel.writeInt(mUid); |
| 5978 |
parcel.writeTypedArrayMap(mHistoricalPackageOps, flags); |
| 5979 |
} |
| 5980 |
|
| 5981 |
private void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 5982 |
visitor.visitHistoricalUidOps(this); |
| 5983 |
final int packageCount = getPackageCount(); |
| 5984 |
for (int i = 0; i < packageCount; i++) { |
| 5985 |
getPackageOpsAt(i).accept(visitor); |
| 5986 |
} |
| 5987 |
} |
| 5988 |
|
| 5989 |
private @NonNull HistoricalPackageOps getOrCreateHistoricalPackageOps( |
| 5990 |
@NonNull String packageName) { |
| 5991 |
if (mHistoricalPackageOps == null) { |
| 5992 |
mHistoricalPackageOps = new ArrayMap<>(); |
| 5993 |
} |
| 5994 |
HistoricalPackageOps historicalPackageOp = mHistoricalPackageOps.get(packageName); |
| 5995 |
if (historicalPackageOp == null) { |
| 5996 |
historicalPackageOp = new HistoricalPackageOps(packageName); |
| 5997 |
mHistoricalPackageOps.put(packageName, historicalPackageOp); |
| 5998 |
} |
| 5999 |
return historicalPackageOp; |
| 6000 |
} |
| 6001 |
|
| 6002 |
|
| 6003 |
public static final @android.annotation.NonNull Creator<HistoricalUidOps> CREATOR = new Creator<HistoricalUidOps>() { |
| 6004 |
@Override |
| 6005 |
public @NonNull HistoricalUidOps createFromParcel(@NonNull Parcel parcel) { |
| 6006 |
return new HistoricalUidOps(parcel); |
| 6007 |
} |
| 6008 |
|
| 6009 |
@Override |
| 6010 |
public @NonNull HistoricalUidOps[] newArray(int size) { |
| 6011 |
return new HistoricalUidOps[size]; |
| 6012 |
} |
| 6013 |
}; |
| 6014 |
|
| 6015 |
@Override |
| 6016 |
public boolean equals(@Nullable Object obj) { |
| 6017 |
if (this == obj) { |
| 6018 |
return true; |
| 6019 |
} |
| 6020 |
if (obj == null || getClass() != obj.getClass()) { |
| 6021 |
return false; |
| 6022 |
} |
| 6023 |
final HistoricalUidOps other = (HistoricalUidOps) obj; |
| 6024 |
if (mUid != other.mUid) { |
| 6025 |
return false; |
| 6026 |
} |
| 6027 |
if (mHistoricalPackageOps == null) { |
| 6028 |
if (other.mHistoricalPackageOps != null) { |
| 6029 |
return false; |
| 6030 |
} |
| 6031 |
} else if (!mHistoricalPackageOps.equals(other.mHistoricalPackageOps)) { |
| 6032 |
return false; |
| 6033 |
} |
| 6034 |
return true; |
| 6035 |
} |
| 6036 |
|
| 6037 |
@Override |
| 6038 |
public int hashCode() { |
| 6039 |
int result = mUid; |
| 6040 |
result = 31 * result + (mHistoricalPackageOps != null |
| 6041 |
? mHistoricalPackageOps.hashCode() : 0); |
| 6042 |
return result; |
| 6043 |
} |
| 6044 |
} |
| 6045 |
|
| 6046 |
|
| 6047 |
|
| 6048 |
|
| 6049 |
|
| 6050 |
|
| 6051 |
@SystemApi |
| 6052 |
public static final class HistoricalPackageOps implements Parcelable { |
| 6053 |
private final @NonNull String mPackageName; |
| 6054 |
private @Nullable ArrayMap<String, AttributedHistoricalOps> mAttributedHistoricalOps; |
| 6055 |
|
| 6056 |
|
| 6057 |
public HistoricalPackageOps(@NonNull String packageName) { |
| 6058 |
mPackageName = packageName; |
| 6059 |
} |
| 6060 |
|
| 6061 |
private HistoricalPackageOps(@NonNull HistoricalPackageOps other) { |
| 6062 |
mPackageName = other.mPackageName; |
| 6063 |
final int opCount = other.getAttributedOpsCount(); |
| 6064 |
for (int i = 0; i < opCount; i++) { |
| 6065 |
final AttributedHistoricalOps origOps = other.getAttributedOpsAt(i); |
| 6066 |
final AttributedHistoricalOps cloneOps = new AttributedHistoricalOps(origOps); |
| 6067 |
if (mAttributedHistoricalOps == null) { |
| 6068 |
mAttributedHistoricalOps = new ArrayMap<>(opCount); |
| 6069 |
} |
| 6070 |
mAttributedHistoricalOps.put(cloneOps.getTag(), cloneOps); |
| 6071 |
} |
| 6072 |
} |
| 6073 |
|
| 6074 |
private HistoricalPackageOps(@NonNull Parcel parcel) { |
| 6075 |
mPackageName = parcel.readString(); |
| 6076 |
mAttributedHistoricalOps = parcel.createTypedArrayMap(AttributedHistoricalOps.CREATOR); |
| 6077 |
} |
| 6078 |
|
| 6079 |
private @Nullable HistoricalPackageOps splice(double fractionToRemove) { |
| 6080 |
HistoricalPackageOps splice = null; |
| 6081 |
final int attributionCount = getAttributedOpsCount(); |
| 6082 |
for (int i = 0; i < attributionCount; i++) { |
| 6083 |
final AttributedHistoricalOps origOps = getAttributedOpsAt(i); |
| 6084 |
final AttributedHistoricalOps spliceOps = origOps.splice(fractionToRemove); |
| 6085 |
if (spliceOps != null) { |
| 6086 |
if (splice == null) { |
| 6087 |
splice = new HistoricalPackageOps(mPackageName); |
| 6088 |
} |
| 6089 |
if (splice.mAttributedHistoricalOps == null) { |
| 6090 |
splice.mAttributedHistoricalOps = new ArrayMap<>(); |
| 6091 |
} |
| 6092 |
splice.mAttributedHistoricalOps.put(spliceOps.getTag(), spliceOps); |
| 6093 |
} |
| 6094 |
} |
| 6095 |
return splice; |
| 6096 |
} |
| 6097 |
|
| 6098 |
private void merge(@NonNull HistoricalPackageOps other) { |
| 6099 |
final int attributionCount = other.getAttributedOpsCount(); |
| 6100 |
for (int i = 0; i < attributionCount; i++) { |
| 6101 |
final AttributedHistoricalOps otherAttributionOps = other.getAttributedOpsAt(i); |
| 6102 |
final AttributedHistoricalOps thisAttributionOps = getAttributedOps( |
| 6103 |
otherAttributionOps.getTag()); |
| 6104 |
if (thisAttributionOps != null) { |
| 6105 |
thisAttributionOps.merge(otherAttributionOps); |
| 6106 |
} else { |
| 6107 |
if (mAttributedHistoricalOps == null) { |
| 6108 |
mAttributedHistoricalOps = new ArrayMap<>(); |
| 6109 |
} |
| 6110 |
mAttributedHistoricalOps.put(otherAttributionOps.getTag(), |
| 6111 |
otherAttributionOps); |
| 6112 |
} |
| 6113 |
} |
| 6114 |
} |
| 6115 |
|
| 6116 |
private void filter(@Nullable String attributionTag, @Nullable String[] opNames, |
| 6117 |
@HistoricalOpsRequestFilter int filter, @OpHistoryFlags int historyFilter, |
| 6118 |
double fractionToRemove, long beginTimeMillis, long endTimeMillis) { |
| 6119 |
final int attributionCount = getAttributedOpsCount(); |
| 6120 |
for (int i = attributionCount - 1; i >= 0; i--) { |
| 6121 |
final AttributedHistoricalOps attributionOps = getAttributedOpsAt(i); |
| 6122 |
if ((filter & FILTER_BY_ATTRIBUTION_TAG) != 0 && !Objects.equals(attributionTag, |
| 6123 |
attributionOps.getTag())) { |
| 6124 |
mAttributedHistoricalOps.removeAt(i); |
| 6125 |
} else { |
| 6126 |
attributionOps.filter(opNames, filter, historyFilter, fractionToRemove, |
| 6127 |
beginTimeMillis, endTimeMillis); |
| 6128 |
if (attributionOps.getOpCount() == 0) { |
| 6129 |
mAttributedHistoricalOps.removeAt(i); |
| 6130 |
} |
| 6131 |
} |
| 6132 |
} |
| 6133 |
} |
| 6134 |
|
| 6135 |
private void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 6136 |
visitor.visitHistoricalPackageOps(this); |
| 6137 |
final int attributionCount = getAttributedOpsCount(); |
| 6138 |
for (int i = 0; i < attributionCount; i++) { |
| 6139 |
getAttributedOpsAt(i).accept(visitor); |
| 6140 |
} |
| 6141 |
} |
| 6142 |
|
| 6143 |
private boolean isEmpty() { |
| 6144 |
final int attributionCount = getAttributedOpsCount(); |
| 6145 |
for (int i = attributionCount - 1; i >= 0; i--) { |
| 6146 |
final AttributedHistoricalOps attributionOps = mAttributedHistoricalOps.valueAt(i); |
| 6147 |
if (!attributionOps.isEmpty()) { |
| 6148 |
return false; |
| 6149 |
} |
| 6150 |
} |
| 6151 |
return true; |
| 6152 |
} |
| 6153 |
|
| 6154 |
private void increaseAccessCount(int opCode, @Nullable String attributionTag, |
| 6155 |
@UidState int uidState, @OpFlags int flags, long increment) { |
| 6156 |
getOrCreateAttributedHistoricalOps(attributionTag).increaseAccessCount( |
| 6157 |
opCode, uidState, flags, increment); |
| 6158 |
} |
| 6159 |
|
| 6160 |
private void increaseRejectCount(int opCode, @Nullable String attributionTag, |
| 6161 |
@UidState int uidState, @OpFlags int flags, long increment) { |
| 6162 |
getOrCreateAttributedHistoricalOps(attributionTag).increaseRejectCount( |
| 6163 |
opCode, uidState, flags, increment); |
| 6164 |
} |
| 6165 |
|
| 6166 |
private void increaseAccessDuration(int opCode, @Nullable String attributionTag, |
| 6167 |
@UidState int uidState, @OpFlags int flags, long increment) { |
| 6168 |
getOrCreateAttributedHistoricalOps(attributionTag).increaseAccessDuration( |
| 6169 |
opCode, uidState, flags, increment); |
| 6170 |
} |
| 6171 |
|
| 6172 |
private void addDiscreteAccess(int opCode, @Nullable String attributionTag, |
| 6173 |
@UidState int uidState, @OpFlags int flag, long discreteAccessTime, |
| 6174 |
long discreteAccessDuration, @Nullable OpEventProxyInfo proxy) { |
| 6175 |
getOrCreateAttributedHistoricalOps(attributionTag).addDiscreteAccess(opCode, uidState, |
| 6176 |
flag, discreteAccessTime, discreteAccessDuration, proxy); |
| 6177 |
} |
| 6178 |
|
| 6179 |
|
| 6180 |
|
| 6181 |
|
| 6182 |
|
| 6183 |
|
| 6184 |
public @NonNull String getPackageName() { |
| 6185 |
return mPackageName; |
| 6186 |
} |
| 6187 |
|
| 6188 |
private @NonNull AttributedHistoricalOps getOrCreateAttributedHistoricalOps( |
| 6189 |
@Nullable String attributionTag) { |
| 6190 |
if (mAttributedHistoricalOps == null) { |
| 6191 |
mAttributedHistoricalOps = new ArrayMap<>(); |
| 6192 |
} |
| 6193 |
AttributedHistoricalOps historicalAttributionOp = mAttributedHistoricalOps.get( |
| 6194 |
attributionTag); |
| 6195 |
if (historicalAttributionOp == null) { |
| 6196 |
historicalAttributionOp = new AttributedHistoricalOps(attributionTag); |
| 6197 |
mAttributedHistoricalOps.put(attributionTag, historicalAttributionOp); |
| 6198 |
} |
| 6199 |
return historicalAttributionOp; |
| 6200 |
} |
| 6201 |
|
| 6202 |
|
| 6203 |
|
| 6204 |
|
| 6205 |
|
| 6206 |
|
| 6207 |
|
| 6208 |
public @IntRange(from = 0) int getOpCount() { |
| 6209 |
int numOps = 0; |
| 6210 |
int numAttributions = getAttributedOpsCount(); |
| 6211 |
|
| 6212 |
for (int code = 0; code < _NUM_OP; code++) { |
| 6213 |
String opName = opToPublicName(code); |
| 6214 |
|
| 6215 |
for (int attributionNum = 0; attributionNum < numAttributions; attributionNum++) { |
| 6216 |
if (getAttributedOpsAt(attributionNum).getOp(opName) != null) { |
| 6217 |
numOps++; |
| 6218 |
break; |
| 6219 |
} |
| 6220 |
} |
| 6221 |
} |
| 6222 |
|
| 6223 |
return numOps; |
| 6224 |
} |
| 6225 |
|
| 6226 |
|
| 6227 |
|
| 6228 |
|
| 6229 |
|
| 6230 |
|
| 6231 |
|
| 6232 |
|
| 6233 |
|
| 6234 |
|
| 6235 |
public @NonNull HistoricalOp getOpAt(@IntRange(from = 0) int index) { |
| 6236 |
int numOpsFound = 0; |
| 6237 |
int numAttributions = getAttributedOpsCount(); |
| 6238 |
|
| 6239 |
for (int code = 0; code < _NUM_OP; code++) { |
| 6240 |
String opName = opToPublicName(code); |
| 6241 |
|
| 6242 |
for (int attributionNum = 0; attributionNum < numAttributions; attributionNum++) { |
| 6243 |
if (getAttributedOpsAt(attributionNum).getOp(opName) != null) { |
| 6244 |
if (numOpsFound == index) { |
| 6245 |
return getOp(opName); |
| 6246 |
} else { |
| 6247 |
numOpsFound++; |
| 6248 |
break; |
| 6249 |
} |
| 6250 |
} |
| 6251 |
} |
| 6252 |
} |
| 6253 |
|
| 6254 |
throw new IndexOutOfBoundsException(); |
| 6255 |
} |
| 6256 |
|
| 6257 |
|
| 6258 |
|
| 6259 |
|
| 6260 |
|
| 6261 |
|
| 6262 |
|
| 6263 |
|
| 6264 |
|
| 6265 |
public @Nullable HistoricalOp getOp(@NonNull String opName) { |
| 6266 |
if (mAttributedHistoricalOps == null) { |
| 6267 |
return null; |
| 6268 |
} |
| 6269 |
|
| 6270 |
HistoricalOp combinedOp = null; |
| 6271 |
int numAttributions = getAttributedOpsCount(); |
| 6272 |
for (int i = 0; i < numAttributions; i++) { |
| 6273 |
HistoricalOp attributionOp = getAttributedOpsAt(i).getOp(opName); |
| 6274 |
if (attributionOp != null) { |
| 6275 |
if (combinedOp == null) { |
| 6276 |
combinedOp = new HistoricalOp(attributionOp); |
| 6277 |
} else { |
| 6278 |
combinedOp.merge(attributionOp); |
| 6279 |
} |
| 6280 |
} |
| 6281 |
} |
| 6282 |
|
| 6283 |
return combinedOp; |
| 6284 |
} |
| 6285 |
|
| 6286 |
@Override |
| 6287 |
public int describeContents() { |
| 6288 |
return 0; |
| 6289 |
} |
| 6290 |
|
| 6291 |
@Override |
| 6292 |
public void writeToParcel(@NonNull Parcel parcel, int flags) { |
| 6293 |
parcel.writeString(mPackageName); |
| 6294 |
parcel.writeTypedArrayMap(mAttributedHistoricalOps, flags); |
| 6295 |
} |
| 6296 |
|
| 6297 |
public static final @android.annotation.NonNull Creator<HistoricalPackageOps> CREATOR = |
| 6298 |
new Creator<HistoricalPackageOps>() { |
| 6299 |
@Override |
| 6300 |
public @NonNull HistoricalPackageOps createFromParcel(@NonNull Parcel parcel) { |
| 6301 |
return new HistoricalPackageOps(parcel); |
| 6302 |
} |
| 6303 |
|
| 6304 |
@Override |
| 6305 |
public @NonNull HistoricalPackageOps[] newArray(int size) { |
| 6306 |
return new HistoricalPackageOps[size]; |
| 6307 |
} |
| 6308 |
}; |
| 6309 |
|
| 6310 |
@Override |
| 6311 |
public boolean equals(@Nullable Object obj) { |
| 6312 |
if (this == obj) { |
| 6313 |
return true; |
| 6314 |
} |
| 6315 |
if (obj == null || getClass() != obj.getClass()) { |
| 6316 |
return false; |
| 6317 |
} |
| 6318 |
final HistoricalPackageOps other = (HistoricalPackageOps) obj; |
| 6319 |
if (!mPackageName.equals(other.mPackageName)) { |
| 6320 |
return false; |
| 6321 |
} |
| 6322 |
if (mAttributedHistoricalOps == null) { |
| 6323 |
if (other.mAttributedHistoricalOps != null) { |
| 6324 |
return false; |
| 6325 |
} |
| 6326 |
} else if (!mAttributedHistoricalOps.equals(other.mAttributedHistoricalOps)) { |
| 6327 |
return false; |
| 6328 |
} |
| 6329 |
return true; |
| 6330 |
} |
| 6331 |
|
| 6332 |
@Override |
| 6333 |
public int hashCode() { |
| 6334 |
int result = mPackageName != null ? mPackageName.hashCode() : 0; |
| 6335 |
result = 31 * result + (mAttributedHistoricalOps != null |
| 6336 |
? mAttributedHistoricalOps.hashCode() : 0); |
| 6337 |
return result; |
| 6338 |
} |
| 6339 |
|
| 6340 |
|
| 6341 |
|
| 6342 |
|
| 6343 |
|
| 6344 |
|
| 6345 |
|
| 6346 |
|
| 6347 |
public @IntRange(from = 0) int getAttributedOpsCount() { |
| 6348 |
if (mAttributedHistoricalOps == null) { |
| 6349 |
return 0; |
| 6350 |
} |
| 6351 |
return mAttributedHistoricalOps.size(); |
| 6352 |
} |
| 6353 |
|
| 6354 |
|
| 6355 |
|
| 6356 |
|
| 6357 |
|
| 6358 |
|
| 6359 |
|
| 6360 |
|
| 6361 |
|
| 6362 |
|
| 6363 |
public @NonNull AttributedHistoricalOps getAttributedOpsAt(@IntRange(from = 0) int index) { |
| 6364 |
if (mAttributedHistoricalOps == null) { |
| 6365 |
throw new IndexOutOfBoundsException(); |
| 6366 |
} |
| 6367 |
return mAttributedHistoricalOps.valueAt(index); |
| 6368 |
} |
| 6369 |
|
| 6370 |
|
| 6371 |
|
| 6372 |
|
| 6373 |
|
| 6374 |
|
| 6375 |
|
| 6376 |
|
| 6377 |
public @Nullable AttributedHistoricalOps getAttributedOps(@Nullable String attributionTag) { |
| 6378 |
if (mAttributedHistoricalOps == null) { |
| 6379 |
return null; |
| 6380 |
} |
| 6381 |
return mAttributedHistoricalOps.get(attributionTag); |
| 6382 |
} |
| 6383 |
} |
| 6384 |
|
| 6385 |
|
| 6386 |
|
| 6387 |
|
| 6388 |
|
| 6389 |
|
| 6390 |
@SystemApi |
| 6391 |
|
| 6392 |
|
| 6393 |
|
| 6394 |
@DataClass.Suppress("getHistoricalOps") |
| 6395 |
public static final class AttributedHistoricalOps implements Parcelable { |
| 6396 |
|
| 6397 |
private final @Nullable String mTag; |
| 6398 |
|
| 6399 |
|
| 6400 |
private @Nullable ArrayMap<String, HistoricalOp> mHistoricalOps; |
| 6401 |
|
| 6402 |
|
| 6403 |
public AttributedHistoricalOps(@NonNull String tag) { |
| 6404 |
mTag = tag; |
| 6405 |
} |
| 6406 |
|
| 6407 |
private AttributedHistoricalOps(@NonNull AttributedHistoricalOps other) { |
| 6408 |
mTag = other.mTag; |
| 6409 |
final int opCount = other.getOpCount(); |
| 6410 |
for (int i = 0; i < opCount; i++) { |
| 6411 |
final HistoricalOp origOp = other.getOpAt(i); |
| 6412 |
final HistoricalOp cloneOp = new HistoricalOp(origOp); |
| 6413 |
if (mHistoricalOps == null) { |
| 6414 |
mHistoricalOps = new ArrayMap<>(opCount); |
| 6415 |
} |
| 6416 |
mHistoricalOps.put(cloneOp.getOpName(), cloneOp); |
| 6417 |
} |
| 6418 |
} |
| 6419 |
|
| 6420 |
private @Nullable AttributedHistoricalOps splice(double fractionToRemove) { |
| 6421 |
AttributedHistoricalOps splice = null; |
| 6422 |
final int opCount = getOpCount(); |
| 6423 |
for (int i = 0; i < opCount; i++) { |
| 6424 |
final HistoricalOp origOps = getOpAt(i); |
| 6425 |
final HistoricalOp spliceOps = origOps.splice(fractionToRemove); |
| 6426 |
if (spliceOps != null) { |
| 6427 |
if (splice == null) { |
| 6428 |
splice = new AttributedHistoricalOps(mTag, null); |
| 6429 |
} |
| 6430 |
if (splice.mHistoricalOps == null) { |
| 6431 |
splice.mHistoricalOps = new ArrayMap<>(); |
| 6432 |
} |
| 6433 |
splice.mHistoricalOps.put(spliceOps.getOpName(), spliceOps); |
| 6434 |
} |
| 6435 |
} |
| 6436 |
return splice; |
| 6437 |
} |
| 6438 |
|
| 6439 |
private void merge(@NonNull AttributedHistoricalOps other) { |
| 6440 |
final int opCount = other.getOpCount(); |
| 6441 |
for (int i = 0; i < opCount; i++) { |
| 6442 |
final HistoricalOp otherOp = other.getOpAt(i); |
| 6443 |
final HistoricalOp thisOp = getOp(otherOp.getOpName()); |
| 6444 |
if (thisOp != null) { |
| 6445 |
thisOp.merge(otherOp); |
| 6446 |
} else { |
| 6447 |
if (mHistoricalOps == null) { |
| 6448 |
mHistoricalOps = new ArrayMap<>(); |
| 6449 |
} |
| 6450 |
mHistoricalOps.put(otherOp.getOpName(), otherOp); |
| 6451 |
} |
| 6452 |
} |
| 6453 |
} |
| 6454 |
|
| 6455 |
private void filter(@Nullable String[] opNames, @HistoricalOpsRequestFilter int filter, |
| 6456 |
@OpHistoryFlags int historyFilter, double scaleFactor, long beginTimeMillis, |
| 6457 |
long endTimeMillis) { |
| 6458 |
final int opCount = getOpCount(); |
| 6459 |
for (int i = opCount - 1; i >= 0; i--) { |
| 6460 |
final HistoricalOp op = mHistoricalOps.valueAt(i); |
| 6461 |
if ((filter & FILTER_BY_OP_NAMES) != 0 && !ArrayUtils.contains(opNames, |
| 6462 |
op.getOpName())) { |
| 6463 |
mHistoricalOps.removeAt(i); |
| 6464 |
} else { |
| 6465 |
op.filter(historyFilter, scaleFactor, beginTimeMillis, endTimeMillis); |
| 6466 |
} |
| 6467 |
} |
| 6468 |
} |
| 6469 |
|
| 6470 |
private boolean isEmpty() { |
| 6471 |
final int opCount = getOpCount(); |
| 6472 |
for (int i = opCount - 1; i >= 0; i--) { |
| 6473 |
final HistoricalOp op = mHistoricalOps.valueAt(i); |
| 6474 |
if (!op.isEmpty()) { |
| 6475 |
return false; |
| 6476 |
} |
| 6477 |
} |
| 6478 |
return true; |
| 6479 |
} |
| 6480 |
|
| 6481 |
private void increaseAccessCount(int opCode, @UidState int uidState, |
| 6482 |
@OpFlags int flags, long increment) { |
| 6483 |
getOrCreateHistoricalOp(opCode).increaseAccessCount(uidState, flags, increment); |
| 6484 |
} |
| 6485 |
|
| 6486 |
private void increaseRejectCount(int opCode, @UidState int uidState, |
| 6487 |
@OpFlags int flags, long increment) { |
| 6488 |
getOrCreateHistoricalOp(opCode).increaseRejectCount(uidState, flags, increment); |
| 6489 |
} |
| 6490 |
|
| 6491 |
private void increaseAccessDuration(int opCode, @UidState int uidState, |
| 6492 |
@OpFlags int flags, long increment) { |
| 6493 |
getOrCreateHistoricalOp(opCode).increaseAccessDuration(uidState, flags, increment); |
| 6494 |
} |
| 6495 |
|
| 6496 |
private void addDiscreteAccess(int opCode, @UidState int uidState, @OpFlags int flag, |
| 6497 |
long discreteAccessTime, long discreteAccessDuration, |
| 6498 |
@Nullable OpEventProxyInfo proxy) { |
| 6499 |
getOrCreateHistoricalOp(opCode).addDiscreteAccess(uidState,flag, discreteAccessTime, |
| 6500 |
discreteAccessDuration, proxy); |
| 6501 |
} |
| 6502 |
|
| 6503 |
|
| 6504 |
|
| 6505 |
|
| 6506 |
|
| 6507 |
|
| 6508 |
|
| 6509 |
public @IntRange(from = 0) int getOpCount() { |
| 6510 |
if (mHistoricalOps == null) { |
| 6511 |
return 0; |
| 6512 |
} |
| 6513 |
return mHistoricalOps.size(); |
| 6514 |
} |
| 6515 |
|
| 6516 |
|
| 6517 |
|
| 6518 |
|
| 6519 |
|
| 6520 |
|
| 6521 |
|
| 6522 |
|
| 6523 |
public @NonNull HistoricalOp getOpAt(@IntRange(from = 0) int index) { |
| 6524 |
if (mHistoricalOps == null) { |
| 6525 |
throw new IndexOutOfBoundsException(); |
| 6526 |
} |
| 6527 |
return mHistoricalOps.valueAt(index); |
| 6528 |
} |
| 6529 |
|
| 6530 |
|
| 6531 |
|
| 6532 |
|
| 6533 |
|
| 6534 |
|
| 6535 |
|
| 6536 |
public @Nullable HistoricalOp getOp(@NonNull String opName) { |
| 6537 |
if (mHistoricalOps == null) { |
| 6538 |
return null; |
| 6539 |
} |
| 6540 |
return mHistoricalOps.get(opName); |
| 6541 |
} |
| 6542 |
|
| 6543 |
private void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 6544 |
visitor.visitHistoricalAttributionOps(this); |
| 6545 |
final int opCount = getOpCount(); |
| 6546 |
for (int i = 0; i < opCount; i++) { |
| 6547 |
getOpAt(i).accept(visitor); |
| 6548 |
} |
| 6549 |
} |
| 6550 |
|
| 6551 |
private @NonNull HistoricalOp getOrCreateHistoricalOp(int opCode) { |
| 6552 |
if (mHistoricalOps == null) { |
| 6553 |
mHistoricalOps = new ArrayMap<>(); |
| 6554 |
} |
| 6555 |
final String opStr = sOpToString[opCode]; |
| 6556 |
HistoricalOp op = mHistoricalOps.get(opStr); |
| 6557 |
if (op == null) { |
| 6558 |
op = new HistoricalOp(opCode); |
| 6559 |
mHistoricalOps.put(opStr, op); |
| 6560 |
} |
| 6561 |
return op; |
| 6562 |
} |
| 6563 |
|
| 6564 |
|
| 6565 |
|
| 6566 |
|
| 6567 |
|
| 6568 |
|
| 6569 |
|
| 6570 |
|
| 6571 |
|
| 6572 |
|
| 6573 |
|
| 6574 |
|
| 6575 |
|
| 6576 |
|
| 6577 |
|
| 6578 |
|
| 6579 |
|
| 6580 |
|
| 6581 |
|
| 6582 |
|
| 6583 |
|
| 6584 |
|
| 6585 |
|
| 6586 |
@DataClass.Generated.Member |
| 6587 |
public AttributedHistoricalOps( |
| 6588 |
@Nullable String tag, |
| 6589 |
@Nullable ArrayMap<String,HistoricalOp> historicalOps) { |
| 6590 |
this.mTag = tag; |
| 6591 |
this.mHistoricalOps = historicalOps; |
| 6592 |
|
| 6593 |
|
| 6594 |
} |
| 6595 |
|
| 6596 |
|
| 6597 |
|
| 6598 |
|
| 6599 |
@DataClass.Generated.Member |
| 6600 |
public @Nullable String getTag() { |
| 6601 |
return mTag; |
| 6602 |
} |
| 6603 |
|
| 6604 |
@Override |
| 6605 |
@DataClass.Generated.Member |
| 6606 |
public boolean equals(@Nullable Object o) { |
| 6607 |
|
| 6608 |
|
| 6609 |
|
| 6610 |
|
| 6611 |
if (this == o) return true; |
| 6612 |
if (o == null || getClass() != o.getClass()) return false; |
| 6613 |
@SuppressWarnings("unchecked") |
| 6614 |
AttributedHistoricalOps that = (AttributedHistoricalOps) o; |
| 6615 |
|
| 6616 |
return true |
| 6617 |
&& Objects.equals(mTag, that.mTag) |
| 6618 |
&& Objects.equals(mHistoricalOps, that.mHistoricalOps); |
| 6619 |
} |
| 6620 |
|
| 6621 |
@Override |
| 6622 |
@DataClass.Generated.Member |
| 6623 |
public int hashCode() { |
| 6624 |
|
| 6625 |
|
| 6626 |
|
| 6627 |
int _hash = 1; |
| 6628 |
_hash = 31 * _hash + Objects.hashCode(mTag); |
| 6629 |
_hash = 31 * _hash + Objects.hashCode(mHistoricalOps); |
| 6630 |
return _hash; |
| 6631 |
} |
| 6632 |
|
| 6633 |
@Override |
| 6634 |
@DataClass.Generated.Member |
| 6635 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 6636 |
|
| 6637 |
|
| 6638 |
|
| 6639 |
byte flg = 0; |
| 6640 |
if (mTag != null) flg |= 0x1; |
| 6641 |
if (mHistoricalOps != null) flg |= 0x2; |
| 6642 |
dest.writeByte(flg); |
| 6643 |
if (mTag != null) dest.writeString(mTag); |
| 6644 |
if (mHistoricalOps != null) dest.writeMap(mHistoricalOps); |
| 6645 |
} |
| 6646 |
|
| 6647 |
@Override |
| 6648 |
@DataClass.Generated.Member |
| 6649 |
public int describeContents() { return 0; } |
| 6650 |
|
| 6651 |
|
| 6652 |
@SuppressWarnings({"unchecked", "RedundantCast"}) |
| 6653 |
@DataClass.Generated.Member |
| 6654 |
AttributedHistoricalOps(@NonNull Parcel in) { |
| 6655 |
|
| 6656 |
|
| 6657 |
|
| 6658 |
byte flg = in.readByte(); |
| 6659 |
String attributionTag = (flg & 0x1) == 0 ? null : in.readString(); |
| 6660 |
ArrayMap<String,HistoricalOp> historicalOps = null; |
| 6661 |
if ((flg & 0x2) != 0) { |
| 6662 |
historicalOps = new ArrayMap(); |
| 6663 |
in.readMap(historicalOps, HistoricalOp.class.getClassLoader()); |
| 6664 |
} |
| 6665 |
|
| 6666 |
this.mTag = attributionTag; |
| 6667 |
this.mHistoricalOps = historicalOps; |
| 6668 |
|
| 6669 |
|
| 6670 |
} |
| 6671 |
|
| 6672 |
@DataClass.Generated.Member |
| 6673 |
public static final @NonNull Parcelable.Creator<AttributedHistoricalOps> CREATOR |
| 6674 |
= new Parcelable.Creator<AttributedHistoricalOps>() { |
| 6675 |
@Override |
| 6676 |
public AttributedHistoricalOps[] newArray(int size) { |
| 6677 |
return new AttributedHistoricalOps[size]; |
| 6678 |
} |
| 6679 |
|
| 6680 |
@Override |
| 6681 |
public AttributedHistoricalOps createFromParcel(@NonNull Parcel in) { |
| 6682 |
return new AttributedHistoricalOps(in); |
| 6683 |
} |
| 6684 |
}; |
| 6685 |
|
| 6686 |
|
| 6687 |
|
| 6688 |
|
| 6689 |
|
| 6690 |
|
| 6691 |
|
| 6692 |
|
| 6693 |
|
| 6694 |
|
| 6695 |
|
| 6696 |
|
| 6697 |
|
| 6698 |
|
| 6699 |
} |
| 6700 |
|
| 6701 |
|
| 6702 |
|
| 6703 |
|
| 6704 |
|
| 6705 |
|
| 6706 |
@SystemApi |
| 6707 |
public static final class HistoricalOp implements Parcelable { |
| 6708 |
private final int mOp; |
| 6709 |
private @Nullable LongSparseLongArray mAccessCount; |
| 6710 |
private @Nullable LongSparseLongArray mRejectCount; |
| 6711 |
private @Nullable LongSparseLongArray mAccessDuration; |
| 6712 |
|
| 6713 |
|
| 6714 |
private @Nullable List<AttributedOpEntry> mDiscreteAccesses; |
| 6715 |
|
| 6716 |
|
| 6717 |
public HistoricalOp(int op) { |
| 6718 |
mOp = op; |
| 6719 |
} |
| 6720 |
|
| 6721 |
private HistoricalOp(@NonNull HistoricalOp other) { |
| 6722 |
mOp = other.mOp; |
| 6723 |
if (other.mAccessCount != null) { |
| 6724 |
mAccessCount = other.mAccessCount.clone(); |
| 6725 |
} |
| 6726 |
if (other.mRejectCount != null) { |
| 6727 |
mRejectCount = other.mRejectCount.clone(); |
| 6728 |
} |
| 6729 |
if (other.mAccessDuration != null) { |
| 6730 |
mAccessDuration = other.mAccessDuration.clone(); |
| 6731 |
} |
| 6732 |
final int historicalOpCount = other.getDiscreteAccessCount(); |
| 6733 |
for (int i = 0; i < historicalOpCount; i++) { |
| 6734 |
final AttributedOpEntry origOp = other.getDiscreteAccessAt(i); |
| 6735 |
final AttributedOpEntry cloneOp = new AttributedOpEntry(origOp); |
| 6736 |
getOrCreateDiscreteAccesses().add(cloneOp); |
| 6737 |
} |
| 6738 |
} |
| 6739 |
|
| 6740 |
private HistoricalOp(@NonNull Parcel parcel) { |
| 6741 |
mOp = parcel.readInt(); |
| 6742 |
mAccessCount = readLongSparseLongArrayFromParcel(parcel); |
| 6743 |
mRejectCount = readLongSparseLongArrayFromParcel(parcel); |
| 6744 |
mAccessDuration = readLongSparseLongArrayFromParcel(parcel); |
| 6745 |
mDiscreteAccesses = readDiscreteAccessArrayFromParcel(parcel); |
| 6746 |
} |
| 6747 |
|
| 6748 |
private void filter(@OpHistoryFlags int historyFlag, double scaleFactor, |
| 6749 |
long beginTimeMillis, long endTimeMillis) { |
| 6750 |
if ((historyFlag & HISTORY_FLAG_AGGREGATE) == 0) { |
| 6751 |
mAccessCount = null; |
| 6752 |
mRejectCount = null; |
| 6753 |
mAccessDuration = null; |
| 6754 |
} else { |
| 6755 |
scale(mAccessCount, scaleFactor); |
| 6756 |
scale(mRejectCount, scaleFactor); |
| 6757 |
scale(mAccessDuration, scaleFactor); |
| 6758 |
} |
| 6759 |
if ((historyFlag & HISTORY_FLAG_DISCRETE) == 0) { |
| 6760 |
mDiscreteAccesses = null; |
| 6761 |
return; |
| 6762 |
} |
| 6763 |
final int discreteOpCount = getDiscreteAccessCount(); |
| 6764 |
for (int i = discreteOpCount - 1; i >= 0; i--) { |
| 6765 |
final AttributedOpEntry op = mDiscreteAccesses.get(i); |
| 6766 |
long opBeginTime = op.getLastAccessTime(OP_FLAGS_ALL); |
| 6767 |
long opEndTime = opBeginTime + op.getLastDuration(OP_FLAGS_ALL); |
| 6768 |
opEndTime = max(opBeginTime, opEndTime); |
| 6769 |
if (opEndTime < beginTimeMillis || opBeginTime > endTimeMillis) { |
| 6770 |
mDiscreteAccesses.remove(i); |
| 6771 |
} |
| 6772 |
} |
| 6773 |
} |
| 6774 |
|
| 6775 |
private boolean isEmpty() { |
| 6776 |
return !hasData(mAccessCount) |
| 6777 |
&& !hasData(mRejectCount) |
| 6778 |
&& !hasData(mAccessDuration) |
| 6779 |
&& (mDiscreteAccesses == null); |
| 6780 |
} |
| 6781 |
|
| 6782 |
private boolean hasData(@NonNull LongSparseLongArray array) { |
| 6783 |
return array != null && array.size() > 0; |
| 6784 |
} |
| 6785 |
|
| 6786 |
private @Nullable HistoricalOp splice(double fractionToRemove) { |
| 6787 |
final HistoricalOp splice = new HistoricalOp(mOp); |
| 6788 |
splice(mAccessCount, splice::getOrCreateAccessCount, fractionToRemove); |
| 6789 |
splice(mRejectCount, splice::getOrCreateRejectCount, fractionToRemove); |
| 6790 |
splice(mAccessDuration, splice::getOrCreateAccessDuration, fractionToRemove); |
| 6791 |
return splice; |
| 6792 |
} |
| 6793 |
|
| 6794 |
private static void splice(@Nullable LongSparseLongArray sourceContainer, |
| 6795 |
@NonNull Supplier<LongSparseLongArray> destContainerProvider, |
| 6796 |
double fractionToRemove) { |
| 6797 |
if (sourceContainer != null) { |
| 6798 |
final int size = sourceContainer.size(); |
| 6799 |
for (int i = 0; i < size; i++) { |
| 6800 |
final long key = sourceContainer.keyAt(i); |
| 6801 |
final long value = sourceContainer.valueAt(i); |
| 6802 |
final long removedFraction = Math.round(value * fractionToRemove); |
| 6803 |
if (removedFraction > 0) { |
| 6804 |
destContainerProvider.get().put(key, removedFraction); |
| 6805 |
sourceContainer.put(key, value - removedFraction); |
| 6806 |
} |
| 6807 |
} |
| 6808 |
} |
| 6809 |
} |
| 6810 |
|
| 6811 |
private void merge(@NonNull HistoricalOp other) { |
| 6812 |
merge(this::getOrCreateAccessCount, other.mAccessCount); |
| 6813 |
merge(this::getOrCreateRejectCount, other.mRejectCount); |
| 6814 |
merge(this::getOrCreateAccessDuration, other.mAccessDuration); |
| 6815 |
|
| 6816 |
if (other.mDiscreteAccesses == null) { |
| 6817 |
return; |
| 6818 |
} |
| 6819 |
if (mDiscreteAccesses == null) { |
| 6820 |
mDiscreteAccesses = new ArrayList(other.mDiscreteAccesses); |
| 6821 |
return; |
| 6822 |
} |
| 6823 |
List<AttributedOpEntry> historicalDiscreteAccesses = new ArrayList<>(); |
| 6824 |
final int otherHistoricalOpCount = other.getDiscreteAccessCount(); |
| 6825 |
final int historicalOpCount = getDiscreteAccessCount(); |
| 6826 |
int i = 0; |
| 6827 |
int j = 0; |
| 6828 |
while (i < otherHistoricalOpCount || j < historicalOpCount) { |
| 6829 |
if (i == otherHistoricalOpCount) { |
| 6830 |
historicalDiscreteAccesses.add(mDiscreteAccesses.get(j++)); |
| 6831 |
} else if (j == historicalOpCount) { |
| 6832 |
historicalDiscreteAccesses.add(other.mDiscreteAccesses.get(i++)); |
| 6833 |
} else if (mDiscreteAccesses.get(j).getLastAccessTime(OP_FLAGS_ALL) |
| 6834 |
< other.mDiscreteAccesses.get(i).getLastAccessTime(OP_FLAGS_ALL)) { |
| 6835 |
historicalDiscreteAccesses.add(mDiscreteAccesses.get(j++)); |
| 6836 |
} else { |
| 6837 |
historicalDiscreteAccesses.add(other.mDiscreteAccesses.get(i++)); |
| 6838 |
} |
| 6839 |
} |
| 6840 |
mDiscreteAccesses = deduplicateDiscreteEvents(historicalDiscreteAccesses); |
| 6841 |
} |
| 6842 |
|
| 6843 |
private void increaseAccessCount(@UidState int uidState, @OpFlags int flags, |
| 6844 |
long increment) { |
| 6845 |
increaseCount(getOrCreateAccessCount(), uidState, flags, increment); |
| 6846 |
} |
| 6847 |
|
| 6848 |
private void increaseRejectCount(@UidState int uidState, @OpFlags int flags, |
| 6849 |
long increment) { |
| 6850 |
increaseCount(getOrCreateRejectCount(), uidState, flags, increment); |
| 6851 |
} |
| 6852 |
|
| 6853 |
private void increaseAccessDuration(@UidState int uidState, @OpFlags int flags, |
| 6854 |
long increment) { |
| 6855 |
increaseCount(getOrCreateAccessDuration(), uidState, flags, increment); |
| 6856 |
} |
| 6857 |
|
| 6858 |
private void increaseCount(@NonNull LongSparseLongArray counts, |
| 6859 |
@UidState int uidState, @OpFlags int flags, long increment) { |
| 6860 |
while (flags != 0) { |
| 6861 |
final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 6862 |
flags &= ~flag; |
| 6863 |
final long key = makeKey(uidState, flag); |
| 6864 |
counts.put(key, counts.get(key) + increment); |
| 6865 |
} |
| 6866 |
} |
| 6867 |
|
| 6868 |
private void addDiscreteAccess(@UidState int uidState, @OpFlags int flag, |
| 6869 |
long discreteAccessTime, long discreteAccessDuration, |
| 6870 |
@Nullable OpEventProxyInfo proxy) { |
| 6871 |
List<AttributedOpEntry> discreteAccesses = getOrCreateDiscreteAccesses(); |
| 6872 |
LongSparseArray<NoteOpEvent> accessEvents = new LongSparseArray<>(); |
| 6873 |
long key = makeKey(uidState, flag); |
| 6874 |
NoteOpEvent note = new NoteOpEvent(discreteAccessTime, discreteAccessDuration, proxy); |
| 6875 |
accessEvents.append(key, note); |
| 6876 |
AttributedOpEntry access = new AttributedOpEntry(mOp, false, accessEvents, null); |
| 6877 |
int insertionPoint = discreteAccesses.size() - 1; |
| 6878 |
for (; insertionPoint >= 0; insertionPoint--) { |
| 6879 |
if (discreteAccesses.get(insertionPoint).getLastAccessTime(OP_FLAGS_ALL) |
| 6880 |
< discreteAccessTime) { |
| 6881 |
break; |
| 6882 |
} |
| 6883 |
} |
| 6884 |
insertionPoint++; |
| 6885 |
if (insertionPoint < discreteAccesses.size() && discreteAccesses.get( |
| 6886 |
insertionPoint).getLastAccessTime(OP_FLAGS_ALL) == discreteAccessTime) { |
| 6887 |
discreteAccesses.set(insertionPoint, mergeAttributedOpEntries( |
| 6888 |
Arrays.asList(discreteAccesses.get(insertionPoint), access))); |
| 6889 |
} else { |
| 6890 |
discreteAccesses.add(insertionPoint, access); |
| 6891 |
} |
| 6892 |
} |
| 6893 |
|
| 6894 |
|
| 6895 |
|
| 6896 |
|
| 6897 |
|
| 6898 |
|
| 6899 |
public @NonNull String getOpName() { |
| 6900 |
return sOpToString[mOp]; |
| 6901 |
} |
| 6902 |
|
| 6903 |
|
| 6904 |
public int getOpCode() { |
| 6905 |
return mOp; |
| 6906 |
} |
| 6907 |
|
| 6908 |
|
| 6909 |
|
| 6910 |
|
| 6911 |
|
| 6912 |
|
| 6913 |
|
| 6914 |
public @IntRange(from = 0) int getDiscreteAccessCount() { |
| 6915 |
if (mDiscreteAccesses == null) { |
| 6916 |
return 0; |
| 6917 |
} |
| 6918 |
return mDiscreteAccesses.size(); |
| 6919 |
} |
| 6920 |
|
| 6921 |
|
| 6922 |
|
| 6923 |
|
| 6924 |
|
| 6925 |
|
| 6926 |
|
| 6927 |
|
| 6928 |
public @NonNull AttributedOpEntry getDiscreteAccessAt(@IntRange(from = 0) int index) { |
| 6929 |
if (mDiscreteAccesses == null) { |
| 6930 |
throw new IndexOutOfBoundsException(); |
| 6931 |
} |
| 6932 |
return mDiscreteAccesses.get(index); |
| 6933 |
} |
| 6934 |
|
| 6935 |
|
| 6936 |
|
| 6937 |
|
| 6938 |
|
| 6939 |
|
| 6940 |
|
| 6941 |
|
| 6942 |
|
| 6943 |
|
| 6944 |
|
| 6945 |
|
| 6946 |
|
| 6947 |
|
| 6948 |
public long getForegroundAccessCount(@OpFlags int flags) { |
| 6949 |
return sumForFlagsInStates(mAccessCount, MAX_PRIORITY_UID_STATE, |
| 6950 |
resolveFirstUnrestrictedUidState(mOp), flags); |
| 6951 |
} |
| 6952 |
|
| 6953 |
|
| 6954 |
|
| 6955 |
|
| 6956 |
|
| 6957 |
|
| 6958 |
|
| 6959 |
|
| 6960 |
|
| 6961 |
|
| 6962 |
|
| 6963 |
|
| 6964 |
|
| 6965 |
|
| 6966 |
@NonNull |
| 6967 |
public List<AttributedOpEntry> getForegroundDiscreteAccesses(@OpFlags int flags) { |
| 6968 |
return listForFlagsInStates(mDiscreteAccesses, MAX_PRIORITY_UID_STATE, |
| 6969 |
resolveFirstUnrestrictedUidState(mOp), flags); |
| 6970 |
} |
| 6971 |
|
| 6972 |
|
| 6973 |
|
| 6974 |
|
| 6975 |
|
| 6976 |
|
| 6977 |
|
| 6978 |
|
| 6979 |
|
| 6980 |
|
| 6981 |
|
| 6982 |
|
| 6983 |
|
| 6984 |
|
| 6985 |
public long getBackgroundAccessCount(@OpFlags int flags) { |
| 6986 |
return sumForFlagsInStates(mAccessCount, resolveLastRestrictedUidState(mOp), |
| 6987 |
MIN_PRIORITY_UID_STATE, flags); |
| 6988 |
} |
| 6989 |
|
| 6990 |
|
| 6991 |
|
| 6992 |
|
| 6993 |
|
| 6994 |
|
| 6995 |
|
| 6996 |
|
| 6997 |
|
| 6998 |
|
| 6999 |
|
| 7000 |
|
| 7001 |
|
| 7002 |
|
| 7003 |
@NonNull |
| 7004 |
public List<AttributedOpEntry> getBackgroundDiscreteAccesses(@OpFlags int flags) { |
| 7005 |
return listForFlagsInStates(mDiscreteAccesses, resolveLastRestrictedUidState(mOp), |
| 7006 |
MIN_PRIORITY_UID_STATE, flags); |
| 7007 |
} |
| 7008 |
|
| 7009 |
|
| 7010 |
|
| 7011 |
|
| 7012 |
|
| 7013 |
|
| 7014 |
|
| 7015 |
|
| 7016 |
|
| 7017 |
|
| 7018 |
|
| 7019 |
|
| 7020 |
|
| 7021 |
|
| 7022 |
|
| 7023 |
|
| 7024 |
|
| 7025 |
|
| 7026 |
|
| 7027 |
|
| 7028 |
|
| 7029 |
public long getAccessCount(@UidState int fromUidState, @UidState int toUidState, |
| 7030 |
@OpFlags int flags) { |
| 7031 |
return sumForFlagsInStates(mAccessCount, fromUidState, toUidState, flags); |
| 7032 |
} |
| 7033 |
|
| 7034 |
|
| 7035 |
|
| 7036 |
|
| 7037 |
|
| 7038 |
|
| 7039 |
|
| 7040 |
|
| 7041 |
|
| 7042 |
|
| 7043 |
|
| 7044 |
|
| 7045 |
|
| 7046 |
|
| 7047 |
|
| 7048 |
@NonNull |
| 7049 |
public List<AttributedOpEntry> getDiscreteAccesses(@UidState int fromUidState, |
| 7050 |
@UidState int toUidState, @OpFlags int flags) { |
| 7051 |
return listForFlagsInStates(mDiscreteAccesses, fromUidState, toUidState, flags); |
| 7052 |
} |
| 7053 |
|
| 7054 |
|
| 7055 |
|
| 7056 |
|
| 7057 |
|
| 7058 |
|
| 7059 |
|
| 7060 |
|
| 7061 |
|
| 7062 |
|
| 7063 |
|
| 7064 |
|
| 7065 |
|
| 7066 |
|
| 7067 |
public long getForegroundRejectCount(@OpFlags int flags) { |
| 7068 |
return sumForFlagsInStates(mRejectCount, MAX_PRIORITY_UID_STATE, |
| 7069 |
resolveFirstUnrestrictedUidState(mOp), flags); |
| 7070 |
} |
| 7071 |
|
| 7072 |
|
| 7073 |
|
| 7074 |
|
| 7075 |
|
| 7076 |
|
| 7077 |
|
| 7078 |
|
| 7079 |
|
| 7080 |
|
| 7081 |
|
| 7082 |
|
| 7083 |
|
| 7084 |
|
| 7085 |
public long getBackgroundRejectCount(@OpFlags int flags) { |
| 7086 |
return sumForFlagsInStates(mRejectCount, resolveLastRestrictedUidState(mOp), |
| 7087 |
MIN_PRIORITY_UID_STATE, flags); |
| 7088 |
} |
| 7089 |
|
| 7090 |
|
| 7091 |
|
| 7092 |
|
| 7093 |
|
| 7094 |
|
| 7095 |
|
| 7096 |
|
| 7097 |
|
| 7098 |
|
| 7099 |
|
| 7100 |
|
| 7101 |
|
| 7102 |
|
| 7103 |
|
| 7104 |
|
| 7105 |
|
| 7106 |
|
| 7107 |
|
| 7108 |
|
| 7109 |
public long getRejectCount(@UidState int fromUidState, @UidState int toUidState, |
| 7110 |
@OpFlags int flags) { |
| 7111 |
return sumForFlagsInStates(mRejectCount, fromUidState, toUidState, flags); |
| 7112 |
} |
| 7113 |
|
| 7114 |
|
| 7115 |
|
| 7116 |
|
| 7117 |
|
| 7118 |
|
| 7119 |
|
| 7120 |
|
| 7121 |
|
| 7122 |
|
| 7123 |
|
| 7124 |
|
| 7125 |
|
| 7126 |
|
| 7127 |
|
| 7128 |
public long getForegroundAccessDuration(@OpFlags int flags) { |
| 7129 |
return sumForFlagsInStates(mAccessDuration, MAX_PRIORITY_UID_STATE, |
| 7130 |
resolveFirstUnrestrictedUidState(mOp), flags); |
| 7131 |
} |
| 7132 |
|
| 7133 |
|
| 7134 |
|
| 7135 |
|
| 7136 |
|
| 7137 |
|
| 7138 |
|
| 7139 |
|
| 7140 |
|
| 7141 |
|
| 7142 |
|
| 7143 |
|
| 7144 |
|
| 7145 |
|
| 7146 |
|
| 7147 |
public long getBackgroundAccessDuration(@OpFlags int flags) { |
| 7148 |
return sumForFlagsInStates(mAccessDuration, resolveLastRestrictedUidState(mOp), |
| 7149 |
MIN_PRIORITY_UID_STATE, flags); |
| 7150 |
} |
| 7151 |
|
| 7152 |
|
| 7153 |
|
| 7154 |
|
| 7155 |
|
| 7156 |
|
| 7157 |
|
| 7158 |
|
| 7159 |
|
| 7160 |
|
| 7161 |
|
| 7162 |
|
| 7163 |
|
| 7164 |
|
| 7165 |
|
| 7166 |
|
| 7167 |
|
| 7168 |
|
| 7169 |
|
| 7170 |
|
| 7171 |
|
| 7172 |
public long getAccessDuration(@UidState int fromUidState, @UidState int toUidState, |
| 7173 |
@OpFlags int flags) { |
| 7174 |
return sumForFlagsInStates(mAccessDuration, fromUidState, toUidState, flags); |
| 7175 |
} |
| 7176 |
|
| 7177 |
@Override |
| 7178 |
public int describeContents() { |
| 7179 |
return 0; |
| 7180 |
} |
| 7181 |
|
| 7182 |
@Override |
| 7183 |
public void writeToParcel(Parcel parcel, int flags) { |
| 7184 |
parcel.writeInt(mOp); |
| 7185 |
writeLongSparseLongArrayToParcel(mAccessCount, parcel); |
| 7186 |
writeLongSparseLongArrayToParcel(mRejectCount, parcel); |
| 7187 |
writeLongSparseLongArrayToParcel(mAccessDuration, parcel); |
| 7188 |
writeDiscreteAccessArrayToParcel(mDiscreteAccesses, parcel, flags); |
| 7189 |
} |
| 7190 |
|
| 7191 |
@Override |
| 7192 |
public boolean equals(@Nullable Object obj) { |
| 7193 |
if (this == obj) { |
| 7194 |
return true; |
| 7195 |
} |
| 7196 |
if (obj == null || getClass() != obj.getClass()) { |
| 7197 |
return false; |
| 7198 |
} |
| 7199 |
final HistoricalOp other = (HistoricalOp) obj; |
| 7200 |
if (mOp != other.mOp) { |
| 7201 |
return false; |
| 7202 |
} |
| 7203 |
if (!equalsLongSparseLongArray(mAccessCount, other.mAccessCount)) { |
| 7204 |
return false; |
| 7205 |
} |
| 7206 |
if (!equalsLongSparseLongArray(mRejectCount, other.mRejectCount)) { |
| 7207 |
return false; |
| 7208 |
} |
| 7209 |
if (!equalsLongSparseLongArray(mAccessDuration, other.mAccessDuration)) { |
| 7210 |
return false; |
| 7211 |
} |
| 7212 |
return mDiscreteAccesses == null ? (other.mDiscreteAccesses == null ? true |
| 7213 |
: false) : mDiscreteAccesses.equals(other.mDiscreteAccesses); |
| 7214 |
} |
| 7215 |
|
| 7216 |
@Override |
| 7217 |
public int hashCode() { |
| 7218 |
int result = mOp; |
| 7219 |
result = 31 * result + Objects.hashCode(mAccessCount); |
| 7220 |
result = 31 * result + Objects.hashCode(mRejectCount); |
| 7221 |
result = 31 * result + Objects.hashCode(mAccessDuration); |
| 7222 |
result = 31 * result + Objects.hashCode(mDiscreteAccesses); |
| 7223 |
return result; |
| 7224 |
} |
| 7225 |
|
| 7226 |
private void accept(@NonNull HistoricalOpsVisitor visitor) { |
| 7227 |
visitor.visitHistoricalOp(this); |
| 7228 |
} |
| 7229 |
|
| 7230 |
private @NonNull LongSparseLongArray getOrCreateAccessCount() { |
| 7231 |
if (mAccessCount == null) { |
| 7232 |
mAccessCount = new LongSparseLongArray(); |
| 7233 |
} |
| 7234 |
return mAccessCount; |
| 7235 |
} |
| 7236 |
|
| 7237 |
private @NonNull LongSparseLongArray getOrCreateRejectCount() { |
| 7238 |
if (mRejectCount == null) { |
| 7239 |
mRejectCount = new LongSparseLongArray(); |
| 7240 |
} |
| 7241 |
return mRejectCount; |
| 7242 |
} |
| 7243 |
|
| 7244 |
private @NonNull LongSparseLongArray getOrCreateAccessDuration() { |
| 7245 |
if (mAccessDuration == null) { |
| 7246 |
mAccessDuration = new LongSparseLongArray(); |
| 7247 |
} |
| 7248 |
return mAccessDuration; |
| 7249 |
} |
| 7250 |
|
| 7251 |
private @NonNull List<AttributedOpEntry> getOrCreateDiscreteAccesses() { |
| 7252 |
if (mDiscreteAccesses == null) { |
| 7253 |
mDiscreteAccesses = new ArrayList<>(); |
| 7254 |
} |
| 7255 |
return mDiscreteAccesses; |
| 7256 |
} |
| 7257 |
|
| 7258 |
|
| 7259 |
|
| 7260 |
|
| 7261 |
|
| 7262 |
|
| 7263 |
|
| 7264 |
|
| 7265 |
private static void scale(@NonNull LongSparseLongArray data, double scaleFactor) { |
| 7266 |
if (data != null) { |
| 7267 |
final int size = data.size(); |
| 7268 |
for (int i = 0; i < size; i++) { |
| 7269 |
data.put(data.keyAt(i), (long) HistoricalOps.round( |
| 7270 |
(double) data.valueAt(i) * scaleFactor)); |
| 7271 |
} |
| 7272 |
} |
| 7273 |
} |
| 7274 |
|
| 7275 |
|
| 7276 |
|
| 7277 |
|
| 7278 |
|
| 7279 |
|
| 7280 |
|
| 7281 |
private static void merge(@NonNull Supplier<LongSparseLongArray> thisSupplier, |
| 7282 |
@Nullable LongSparseLongArray other) { |
| 7283 |
if (other != null) { |
| 7284 |
final int otherSize = other.size(); |
| 7285 |
for (int i = 0; i < otherSize; i++) { |
| 7286 |
final LongSparseLongArray that = thisSupplier.get(); |
| 7287 |
final long otherKey = other.keyAt(i); |
| 7288 |
final long otherValue = other.valueAt(i); |
| 7289 |
that.put(otherKey, that.get(otherKey) + otherValue); |
| 7290 |
} |
| 7291 |
} |
| 7292 |
} |
| 7293 |
|
| 7294 |
|
| 7295 |
public @Nullable LongSparseArray<Object> collectKeys() { |
| 7296 |
LongSparseArray<Object> result = AppOpsManager.collectKeys(mAccessCount, |
| 7297 |
null ); |
| 7298 |
result = AppOpsManager.collectKeys(mRejectCount, result); |
| 7299 |
result = AppOpsManager.collectKeys(mAccessDuration, result); |
| 7300 |
return result; |
| 7301 |
} |
| 7302 |
|
| 7303 |
public static final @android.annotation.NonNull Creator<HistoricalOp> CREATOR = |
| 7304 |
new Creator<HistoricalOp>() { |
| 7305 |
@Override |
| 7306 |
public @NonNull HistoricalOp createFromParcel(@NonNull Parcel source) { |
| 7307 |
return new HistoricalOp(source); |
| 7308 |
} |
| 7309 |
|
| 7310 |
@Override |
| 7311 |
public @NonNull HistoricalOp[] newArray(int size) { |
| 7312 |
return new HistoricalOp[size]; |
| 7313 |
} |
| 7314 |
}; |
| 7315 |
} |
| 7316 |
|
| 7317 |
|
| 7318 |
|
| 7319 |
|
| 7320 |
|
| 7321 |
|
| 7322 |
|
| 7323 |
|
| 7324 |
|
| 7325 |
|
| 7326 |
|
| 7327 |
private static long sumForFlagsInStates(@Nullable LongSparseLongArray counts, |
| 7328 |
@UidState int beginUidState, @UidState int endUidState, @OpFlags int flags) { |
| 7329 |
if (counts == null) { |
| 7330 |
return 0; |
| 7331 |
} |
| 7332 |
long sum = 0; |
| 7333 |
while (flags != 0) { |
| 7334 |
final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 7335 |
flags &= ~flag; |
| 7336 |
for (int uidState : UID_STATES) { |
| 7337 |
if (uidState < beginUidState || uidState > endUidState) { |
| 7338 |
continue; |
| 7339 |
} |
| 7340 |
final long key = makeKey(uidState, flag); |
| 7341 |
sum += counts.get(key); |
| 7342 |
} |
| 7343 |
} |
| 7344 |
return sum; |
| 7345 |
} |
| 7346 |
|
| 7347 |
|
| 7348 |
|
| 7349 |
|
| 7350 |
|
| 7351 |
|
| 7352 |
|
| 7353 |
|
| 7354 |
|
| 7355 |
|
| 7356 |
private static List<AttributedOpEntry> listForFlagsInStates(List<AttributedOpEntry> accesses, |
| 7357 |
@UidState int beginUidState, @UidState int endUidState, @OpFlags int flags) { |
| 7358 |
List<AttributedOpEntry> result = new ArrayList<>(); |
| 7359 |
if (accesses == null) { |
| 7360 |
return result; |
| 7361 |
} |
| 7362 |
int nAccesses = accesses.size(); |
| 7363 |
for (int i = 0; i < nAccesses; i++) { |
| 7364 |
AttributedOpEntry entry = accesses.get(i); |
| 7365 |
if (entry.getLastAccessTime(beginUidState, endUidState, flags) == -1) { |
| 7366 |
continue; |
| 7367 |
} |
| 7368 |
result.add(entry); |
| 7369 |
} |
| 7370 |
return deduplicateDiscreteEvents(result); |
| 7371 |
} |
| 7372 |
|
| 7373 |
|
| 7374 |
|
| 7375 |
|
| 7376 |
public interface OnOpChangedListener { |
| 7377 |
public void onOpChanged(String op, String packageName); |
| 7378 |
} |
| 7379 |
|
| 7380 |
|
| 7381 |
|
| 7382 |
|
| 7383 |
public interface OnOpActiveChangedListener { |
| 7384 |
|
| 7385 |
|
| 7386 |
|
| 7387 |
|
| 7388 |
|
| 7389 |
|
| 7390 |
|
| 7391 |
void onOpActiveChanged(@NonNull String op, int uid, @NonNull String packageName, |
| 7392 |
boolean active); |
| 7393 |
|
| 7394 |
|
| 7395 |
|
| 7396 |
|
| 7397 |
|
| 7398 |
|
| 7399 |
|
| 7400 |
|
| 7401 |
|
| 7402 |
|
| 7403 |
|
| 7404 |
|
| 7405 |
|
| 7406 |
@TestApi |
| 7407 |
default void onOpActiveChanged(@NonNull String op, int uid, @NonNull String packageName, |
| 7408 |
@Nullable String attributionTag, boolean active, @AttributionFlags |
| 7409 |
int attributionFlags, int attributionChainId) { |
| 7410 |
onOpActiveChanged(op, uid, packageName, active); |
| 7411 |
} |
| 7412 |
} |
| 7413 |
|
| 7414 |
|
| 7415 |
|
| 7416 |
|
| 7417 |
|
| 7418 |
|
| 7419 |
public interface OnOpNotedListener { |
| 7420 |
|
| 7421 |
|
| 7422 |
|
| 7423 |
|
| 7424 |
|
| 7425 |
|
| 7426 |
|
| 7427 |
|
| 7428 |
|
| 7429 |
void onOpNoted(int code, int uid, String packageName, String attributionTag, |
| 7430 |
@OpFlags int flags, @Mode int result); |
| 7431 |
} |
| 7432 |
|
| 7433 |
|
| 7434 |
|
| 7435 |
|
| 7436 |
|
| 7437 |
|
| 7438 |
public static class OnOpChangedInternalListener implements OnOpChangedListener { |
| 7439 |
public void onOpChanged(String op, String packageName) { } |
| 7440 |
public void onOpChanged(int op, String packageName) { } |
| 7441 |
} |
| 7442 |
|
| 7443 |
|
| 7444 |
|
| 7445 |
|
| 7446 |
|
| 7447 |
|
| 7448 |
public interface OnOpActiveChangedInternalListener extends OnOpActiveChangedListener { |
| 7449 |
default void onOpActiveChanged(String op, int uid, String packageName, boolean active) { } |
| 7450 |
default void onOpActiveChanged(int op, int uid, String packageName, boolean active) { } |
| 7451 |
} |
| 7452 |
|
| 7453 |
|
| 7454 |
|
| 7455 |
|
| 7456 |
|
| 7457 |
|
| 7458 |
public interface OnOpStartedListener { |
| 7459 |
|
| 7460 |
|
| 7461 |
|
| 7462 |
|
| 7463 |
|
| 7464 |
public int START_TYPE_FAILED = 0; |
| 7465 |
|
| 7466 |
|
| 7467 |
|
| 7468 |
|
| 7469 |
|
| 7470 |
public int START_TYPE_STARTED = 1; |
| 7471 |
|
| 7472 |
|
| 7473 |
|
| 7474 |
|
| 7475 |
|
| 7476 |
public int START_TYPE_RESUMED = 2; |
| 7477 |
|
| 7478 |
|
| 7479 |
@Retention(RetentionPolicy.SOURCE) |
| 7480 |
@IntDef(flag = true, prefix = { "TYPE_" }, value = { |
| 7481 |
START_TYPE_FAILED, |
| 7482 |
START_TYPE_STARTED, |
| 7483 |
START_TYPE_RESUMED |
| 7484 |
}) |
| 7485 |
public @interface StartedType {} |
| 7486 |
|
| 7487 |
|
| 7488 |
|
| 7489 |
|
| 7490 |
|
| 7491 |
|
| 7492 |
|
| 7493 |
|
| 7494 |
|
| 7495 |
|
| 7496 |
|
| 7497 |
|
| 7498 |
void onOpStarted(int op, int uid, String packageName, String attributionTag, |
| 7499 |
@OpFlags int flags, @Mode int result); |
| 7500 |
|
| 7501 |
|
| 7502 |
|
| 7503 |
|
| 7504 |
|
| 7505 |
|
| 7506 |
|
| 7507 |
|
| 7508 |
|
| 7509 |
|
| 7510 |
|
| 7511 |
|
| 7512 |
|
| 7513 |
|
| 7514 |
|
| 7515 |
|
| 7516 |
|
| 7517 |
default void onOpStarted(int op, int uid, String packageName, String attributionTag, |
| 7518 |
@OpFlags int flags, @Mode int result, @StartedType int startType, |
| 7519 |
@AttributionFlags int attributionFlags, int attributionChainId) { |
| 7520 |
if (startType != START_TYPE_RESUMED) { |
| 7521 |
onOpStarted(op, uid, packageName, attributionTag, flags, result); |
| 7522 |
} |
| 7523 |
} |
| 7524 |
} |
| 7525 |
|
| 7526 |
AppOpsManager(Context context, IAppOpsService service) { |
| 7527 |
mContext = context; |
| 7528 |
mService = service; |
| 7529 |
|
| 7530 |
if (mContext != null) { |
| 7531 |
final PackageManager pm = mContext.getPackageManager(); |
| 7532 |
try { |
| 7533 |
if (pm != null && pm.checkPermission(Manifest.permission.READ_DEVICE_CONFIG, |
| 7534 |
mContext.getPackageName()) == PackageManager.PERMISSION_GRANTED) { |
| 7535 |
DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_PRIVACY, |
| 7536 |
mContext.getMainExecutor(), properties -> { |
| 7537 |
if (properties.getKeyset().contains(FULL_LOG)) { |
| 7538 |
sFullLog = properties.getBoolean(FULL_LOG, false); |
| 7539 |
} |
| 7540 |
}); |
| 7541 |
return; |
| 7542 |
} |
| 7543 |
} catch (Exception e) { |
| 7544 |
|
| 7545 |
|
| 7546 |
} |
| 7547 |
} |
| 7548 |
sFullLog = false; |
| 7549 |
} |
| 7550 |
|
| 7551 |
|
| 7552 |
|
| 7553 |
|
| 7554 |
|
| 7555 |
|
| 7556 |
|
| 7557 |
|
| 7558 |
|
| 7559 |
|
| 7560 |
|
| 7561 |
|
| 7562 |
|
| 7563 |
@SystemApi |
| 7564 |
@RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
| 7565 |
public @NonNull List<AppOpsManager.PackageOps> getPackagesForOps(@Nullable String[] ops) { |
| 7566 |
final int opCount = ops.length; |
| 7567 |
final int[] opCodes = new int[opCount]; |
| 7568 |
for (int i = 0; i < opCount; i++) { |
| 7569 |
opCodes[i] = sOpStrToOp.get(ops[i]); |
| 7570 |
} |
| 7571 |
final List<AppOpsManager.PackageOps> result = getPackagesForOps(opCodes); |
| 7572 |
return (result != null) ? result : Collections.emptyList(); |
| 7573 |
} |
| 7574 |
|
| 7575 |
|
| 7576 |
|
| 7577 |
|
| 7578 |
|
| 7579 |
|
| 7580 |
|
| 7581 |
|
| 7582 |
|
| 7583 |
|
| 7584 |
|
| 7585 |
|
| 7586 |
|
| 7587 |
@RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
| 7588 |
@UnsupportedAppUsage |
| 7589 |
public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops) { |
| 7590 |
try { |
| 7591 |
return mService.getPackagesForOps(ops); |
| 7592 |
} catch (RemoteException e) { |
| 7593 |
throw e.rethrowFromSystemServer(); |
| 7594 |
} |
| 7595 |
} |
| 7596 |
|
| 7597 |
|
| 7598 |
|
| 7599 |
|
| 7600 |
|
| 7601 |
|
| 7602 |
|
| 7603 |
|
| 7604 |
|
| 7605 |
|
| 7606 |
|
| 7607 |
|
| 7608 |
|
| 7609 |
|
| 7610 |
|
| 7611 |
|
| 7612 |
|
| 7613 |
|
| 7614 |
|
| 7615 |
|
| 7616 |
|
| 7617 |
@Deprecated |
| 7618 |
@SystemApi |
| 7619 |
@RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
| 7620 |
public @NonNull List<PackageOps> getOpsForPackage(int uid, @NonNull String packageName, |
| 7621 |
@Nullable int[] ops) { |
| 7622 |
try { |
| 7623 |
return mService.getOpsForPackage(uid, packageName, ops); |
| 7624 |
} catch (RemoteException e) { |
| 7625 |
throw e.rethrowFromSystemServer(); |
| 7626 |
} |
| 7627 |
} |
| 7628 |
|
| 7629 |
|
| 7630 |
|
| 7631 |
|
| 7632 |
|
| 7633 |
|
| 7634 |
|
| 7635 |
|
| 7636 |
|
| 7637 |
|
| 7638 |
|
| 7639 |
|
| 7640 |
|
| 7641 |
|
| 7642 |
|
| 7643 |
|
| 7644 |
|
| 7645 |
@SystemApi |
| 7646 |
@RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
| 7647 |
public @NonNull List<AppOpsManager.PackageOps> getOpsForPackage(int uid, |
| 7648 |
@NonNull String packageName, @Nullable String... ops) { |
| 7649 |
int[] opCodes = null; |
| 7650 |
if (ops != null) { |
| 7651 |
opCodes = new int[ops.length]; |
| 7652 |
for (int i = 0; i < ops.length; i++) { |
| 7653 |
opCodes[i] = strOpToOp(ops[i]); |
| 7654 |
} |
| 7655 |
} |
| 7656 |
try { |
| 7657 |
final List<PackageOps> result = mService.getOpsForPackage(uid, packageName, opCodes); |
| 7658 |
if (result == null) { |
| 7659 |
return Collections.emptyList(); |
| 7660 |
} |
| 7661 |
return result; |
| 7662 |
} catch (RemoteException e) { |
| 7663 |
throw e.rethrowFromSystemServer(); |
| 7664 |
} |
| 7665 |
} |
| 7666 |
|
| 7667 |
|
| 7668 |
|
| 7669 |
|
| 7670 |
|
| 7671 |
|
| 7672 |
|
| 7673 |
|
| 7674 |
|
| 7675 |
|
| 7676 |
|
| 7677 |
|
| 7678 |
|
| 7679 |
@SystemApi |
| 7680 |
@RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) |
| 7681 |
public void getHistoricalOps(@NonNull HistoricalOpsRequest request, |
| 7682 |
@NonNull Executor executor, @NonNull Consumer<HistoricalOps> callback) { |
| 7683 |
Objects.requireNonNull(executor, "executor cannot be null"); |
| 7684 |
Objects.requireNonNull(callback, "callback cannot be null"); |
| 7685 |
try { |
| 7686 |
mService.getHistoricalOps(request.mUid, request.mPackageName, request.mAttributionTag, |
| 7687 |
request.mOpNames, request.mHistoryFlags, request.mFilter, |
| 7688 |
request.mBeginTimeMillis, request.mEndTimeMillis, request.mFlags, |
| 7689 |
new RemoteCallback((result) -> { |
| 7690 |
final HistoricalOps ops = result.getParcelable(KEY_HISTORICAL_OPS); |
| 7691 |
final long identity = Binder.clearCallingIdentity(); |
| 7692 |
try { |
| 7693 |
executor.execute(() -> callback.accept(ops)); |
| 7694 |
} finally { |
| 7695 |
Binder.restoreCallingIdentity(identity); |
| 7696 |
} |
| 7697 |
})); |
| 7698 |
} catch (RemoteException e) { |
| 7699 |
throw e.rethrowFromSystemServer(); |
| 7700 |
} |
| 7701 |
} |
| 7702 |
|
| 7703 |
|
| 7704 |
|
| 7705 |
|
| 7706 |
|
| 7707 |
|
| 7708 |
|
| 7709 |
|
| 7710 |
|
| 7711 |
|
| 7712 |
|
| 7713 |
|
| 7714 |
|
| 7715 |
|
| 7716 |
|
| 7717 |
|
| 7718 |
|
| 7719 |
@TestApi |
| 7720 |
@RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 7721 |
public void getHistoricalOpsFromDiskRaw(@NonNull HistoricalOpsRequest request, |
| 7722 |
@Nullable Executor executor, @NonNull Consumer<HistoricalOps> callback) { |
| 7723 |
Objects.requireNonNull(executor, "executor cannot be null"); |
| 7724 |
Objects.requireNonNull(callback, "callback cannot be null"); |
| 7725 |
try { |
| 7726 |
mService.getHistoricalOpsFromDiskRaw(request.mUid, request.mPackageName, |
| 7727 |
request.mAttributionTag, request.mOpNames, request.mHistoryFlags, |
| 7728 |
request.mFilter, request.mBeginTimeMillis, request.mEndTimeMillis, |
| 7729 |
request.mFlags, new RemoteCallback((result) -> { |
| 7730 |
final HistoricalOps ops = result.getParcelable(KEY_HISTORICAL_OPS); |
| 7731 |
final long identity = Binder.clearCallingIdentity(); |
| 7732 |
try { |
| 7733 |
executor.execute(() -> callback.accept(ops)); |
| 7734 |
} finally { |
| 7735 |
Binder.restoreCallingIdentity(identity); |
| 7736 |
} |
| 7737 |
})); |
| 7738 |
} catch (RemoteException e) { |
| 7739 |
throw e.rethrowFromSystemServer(); |
| 7740 |
} |
| 7741 |
} |
| 7742 |
|
| 7743 |
|
| 7744 |
|
| 7745 |
|
| 7746 |
|
| 7747 |
|
| 7748 |
@TestApi |
| 7749 |
@RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 7750 |
public void reloadNonHistoricalState() { |
| 7751 |
try { |
| 7752 |
mService.reloadNonHistoricalState(); |
| 7753 |
} catch (RemoteException e) { |
| 7754 |
throw e.rethrowFromSystemServer(); |
| 7755 |
} |
| 7756 |
} |
| 7757 |
|
| 7758 |
|
| 7759 |
|
| 7760 |
|
| 7761 |
|
| 7762 |
|
| 7763 |
|
| 7764 |
|
| 7765 |
|
| 7766 |
|
| 7767 |
|
| 7768 |
@RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
| 7769 |
public void setUidMode(int code, int uid, @Mode int mode) { |
| 7770 |
try { |
| 7771 |
mService.setUidMode(code, uid, mode); |
| 7772 |
} catch (RemoteException e) { |
| 7773 |
throw e.rethrowFromSystemServer(); |
| 7774 |
} |
| 7775 |
} |
| 7776 |
|
| 7777 |
|
| 7778 |
|
| 7779 |
|
| 7780 |
|
| 7781 |
|
| 7782 |
|
| 7783 |
|
| 7784 |
|
| 7785 |
|
| 7786 |
|
| 7787 |
@SystemApi |
| 7788 |
@RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
| 7789 |
public void setUidMode(@NonNull String appOp, int uid, @Mode int mode) { |
| 7790 |
try { |
| 7791 |
mService.setUidMode(AppOpsManager.strOpToOp(appOp), uid, mode); |
| 7792 |
} catch (RemoteException e) { |
| 7793 |
throw e.rethrowFromSystemServer(); |
| 7794 |
} |
| 7795 |
} |
| 7796 |
|
| 7797 |
|
| 7798 |
public void setUserRestriction(int code, boolean restricted, IBinder token) { |
| 7799 |
setUserRestriction(code, restricted, token, null); |
| 7800 |
} |
| 7801 |
|
| 7802 |
|
| 7803 |
|
| 7804 |
|
| 7805 |
|
| 7806 |
public void setUserRestriction(int code, boolean restricted, IBinder token, |
| 7807 |
@Nullable PackageTagsList excludedPackageTags) { |
| 7808 |
setUserRestrictionForUser(code, restricted, token, excludedPackageTags, |
| 7809 |
mContext.getUserId()); |
| 7810 |
} |
| 7811 |
|
| 7812 |
|
| 7813 |
|
| 7814 |
|
| 7815 |
|
| 7816 |
public void setUserRestrictionForUser(int code, boolean restricted, IBinder token, |
| 7817 |
@Nullable PackageTagsList excludedPackageTags, int userId) { |
| 7818 |
try { |
| 7819 |
mService.setUserRestriction(code, restricted, token, userId, excludedPackageTags); |
| 7820 |
} catch (RemoteException e) { |
| 7821 |
throw e.rethrowFromSystemServer(); |
| 7822 |
} |
| 7823 |
} |
| 7824 |
|
| 7825 |
|
| 7826 |
@UnsupportedAppUsage |
| 7827 |
@TestApi |
| 7828 |
@RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
| 7829 |
public void setMode(int code, int uid, String packageName, @Mode int mode) { |
| 7830 |
try { |
| 7831 |
mService.setMode(code, uid, packageName, mode); |
| 7832 |
} catch (RemoteException e) { |
| 7833 |
throw e.rethrowFromSystemServer(); |
| 7834 |
} |
| 7835 |
} |
| 7836 |
|
| 7837 |
|
| 7838 |
|
| 7839 |
|
| 7840 |
|
| 7841 |
|
| 7842 |
|
| 7843 |
|
| 7844 |
|
| 7845 |
|
| 7846 |
|
| 7847 |
|
| 7848 |
@SystemApi |
| 7849 |
@RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
| 7850 |
public void setMode(@NonNull String op, int uid, @Nullable String packageName, |
| 7851 |
@Mode int mode) { |
| 7852 |
try { |
| 7853 |
mService.setMode(strOpToOp(op), uid, packageName, mode); |
| 7854 |
} catch (RemoteException e) { |
| 7855 |
throw e.rethrowFromSystemServer(); |
| 7856 |
} |
| 7857 |
} |
| 7858 |
|
| 7859 |
|
| 7860 |
|
| 7861 |
|
| 7862 |
|
| 7863 |
|
| 7864 |
|
| 7865 |
|
| 7866 |
|
| 7867 |
|
| 7868 |
|
| 7869 |
|
| 7870 |
@RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
| 7871 |
@UnsupportedAppUsage |
| 7872 |
public void setRestriction(int code, @AttributeUsage int usage, @Mode int mode, |
| 7873 |
String[] exceptionPackages) { |
| 7874 |
try { |
| 7875 |
final int uid = Binder.getCallingUid(); |
| 7876 |
mService.setAudioRestriction(code, usage, uid, mode, exceptionPackages); |
| 7877 |
} catch (RemoteException e) { |
| 7878 |
throw e.rethrowFromSystemServer(); |
| 7879 |
} |
| 7880 |
} |
| 7881 |
|
| 7882 |
|
| 7883 |
@RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES) |
| 7884 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 7885 |
public void resetAllModes() { |
| 7886 |
try { |
| 7887 |
mService.resetAllModes(mContext.getUserId(), null); |
| 7888 |
} catch (RemoteException e) { |
| 7889 |
throw e.rethrowFromSystemServer(); |
| 7890 |
} |
| 7891 |
} |
| 7892 |
|
| 7893 |
|
| 7894 |
|
| 7895 |
|
| 7896 |
|
| 7897 |
|
| 7898 |
|
| 7899 |
|
| 7900 |
|
| 7901 |
|
| 7902 |
|
| 7903 |
|
| 7904 |
public static @Nullable String permissionToOp(@NonNull String permission) { |
| 7905 |
final Integer opCode = sPermToOp.get(permission); |
| 7906 |
if (opCode == null) { |
| 7907 |
return null; |
| 7908 |
} |
| 7909 |
return sOpToString[opCode]; |
| 7910 |
} |
| 7911 |
|
| 7912 |
|
| 7913 |
|
| 7914 |
|
| 7915 |
|
| 7916 |
|
| 7917 |
|
| 7918 |
|
| 7919 |
|
| 7920 |
|
| 7921 |
public static @Nullable String resolvePackageName(int uid, @Nullable String packageName) { |
| 7922 |
if (uid == Process.ROOT_UID) { |
| 7923 |
return "root"; |
| 7924 |
} else if (uid == Process.SHELL_UID) { |
| 7925 |
return "com.android.shell"; |
| 7926 |
} else if (uid == Process.MEDIA_UID) { |
| 7927 |
return "media"; |
| 7928 |
} else if (uid == Process.AUDIOSERVER_UID) { |
| 7929 |
return "audioserver"; |
| 7930 |
} else if (uid == Process.CAMERASERVER_UID) { |
| 7931 |
return "cameraserver"; |
| 7932 |
} else if (uid == Process.SYSTEM_UID && packageName == null) { |
| 7933 |
return "android"; |
| 7934 |
} |
| 7935 |
return packageName; |
| 7936 |
} |
| 7937 |
|
| 7938 |
|
| 7939 |
|
| 7940 |
|
| 7941 |
|
| 7942 |
|
| 7943 |
|
| 7944 |
|
| 7945 |
|
| 7946 |
public void startWatchingMode(@NonNull String op, @Nullable String packageName, |
| 7947 |
@NonNull final OnOpChangedListener callback) { |
| 7948 |
startWatchingMode(strOpToOp(op), packageName, callback); |
| 7949 |
} |
| 7950 |
|
| 7951 |
|
| 7952 |
|
| 7953 |
|
| 7954 |
|
| 7955 |
|
| 7956 |
|
| 7957 |
|
| 7958 |
|
| 7959 |
|
| 7960 |
public void startWatchingMode(@NonNull String op, @Nullable String packageName, int flags, |
| 7961 |
@NonNull final OnOpChangedListener callback) { |
| 7962 |
startWatchingMode(strOpToOp(op), packageName, flags, callback); |
| 7963 |
} |
| 7964 |
|
| 7965 |
|
| 7966 |
|
| 7967 |
|
| 7968 |
|
| 7969 |
|
| 7970 |
|
| 7971 |
|
| 7972 |
|
| 7973 |
|
| 7974 |
|
| 7975 |
|
| 7976 |
@RequiresPermission(value=android.Manifest.permission.WATCH_APPOPS, conditional=true) |
| 7977 |
public void startWatchingMode(int op, String packageName, final OnOpChangedListener callback) { |
| 7978 |
startWatchingMode(op, packageName, 0, callback); |
| 7979 |
} |
| 7980 |
|
| 7981 |
|
| 7982 |
|
| 7983 |
|
| 7984 |
|
| 7985 |
|
| 7986 |
|
| 7987 |
|
| 7988 |
|
| 7989 |
|
| 7990 |
|
| 7991 |
|
| 7992 |
|
| 7993 |
@RequiresPermission(value=android.Manifest.permission.WATCH_APPOPS, conditional=true) |
| 7994 |
public void startWatchingMode(int op, String packageName, int flags, |
| 7995 |
final OnOpChangedListener callback) { |
| 7996 |
synchronized (mModeWatchers) { |
| 7997 |
IAppOpsCallback cb = mModeWatchers.get(callback); |
| 7998 |
if (cb == null) { |
| 7999 |
cb = new IAppOpsCallback.Stub() { |
| 8000 |
public void opChanged(int op, int uid, String packageName) { |
| 8001 |
if (callback instanceof OnOpChangedInternalListener) { |
| 8002 |
((OnOpChangedInternalListener)callback).onOpChanged(op, packageName); |
| 8003 |
} |
| 8004 |
if (sOpToString[op] != null) { |
| 8005 |
callback.onOpChanged(sOpToString[op], packageName); |
| 8006 |
} |
| 8007 |
} |
| 8008 |
}; |
| 8009 |
mModeWatchers.put(callback, cb); |
| 8010 |
} |
| 8011 |
|
| 8012 |
|
| 8013 |
if (!Compatibility.isChangeEnabled( |
| 8014 |
CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE)) { |
| 8015 |
flags |= CALL_BACK_ON_SWITCHED_OP; |
| 8016 |
} |
| 8017 |
|
| 8018 |
try { |
| 8019 |
mService.startWatchingModeWithFlags(op, packageName, flags, cb); |
| 8020 |
} catch (RemoteException e) { |
| 8021 |
throw e.rethrowFromSystemServer(); |
| 8022 |
} |
| 8023 |
} |
| 8024 |
} |
| 8025 |
|
| 8026 |
|
| 8027 |
|
| 8028 |
|
| 8029 |
|
| 8030 |
public void stopWatchingMode(@NonNull OnOpChangedListener callback) { |
| 8031 |
synchronized (mModeWatchers) { |
| 8032 |
IAppOpsCallback cb = mModeWatchers.remove(callback); |
| 8033 |
if (cb != null) { |
| 8034 |
try { |
| 8035 |
mService.stopWatchingMode(cb); |
| 8036 |
} catch (RemoteException e) { |
| 8037 |
throw e.rethrowFromSystemServer(); |
| 8038 |
} |
| 8039 |
} |
| 8040 |
} |
| 8041 |
} |
| 8042 |
|
| 8043 |
|
| 8044 |
@Deprecated |
| 8045 |
public void startWatchingActive(@NonNull int[] ops, |
| 8046 |
@NonNull OnOpActiveChangedListener callback) { |
| 8047 |
final String[] strOps = new String[ops.length]; |
| 8048 |
for (int i = 0; i < ops.length; i++) { |
| 8049 |
strOps[i] = opToPublicName(ops[i]); |
| 8050 |
} |
| 8051 |
startWatchingActive(strOps, mContext.getMainExecutor(), callback); |
| 8052 |
} |
| 8053 |
|
| 8054 |
|
| 8055 |
|
| 8056 |
|
| 8057 |
|
| 8058 |
|
| 8059 |
|
| 8060 |
|
| 8061 |
|
| 8062 |
|
| 8063 |
|
| 8064 |
|
| 8065 |
|
| 8066 |
|
| 8067 |
|
| 8068 |
|
| 8069 |
|
| 8070 |
|
| 8071 |
public void startWatchingActive(@NonNull String[] ops, |
| 8072 |
@CallbackExecutor @NonNull Executor executor, |
| 8073 |
@NonNull OnOpActiveChangedListener callback) { |
| 8074 |
Objects.requireNonNull(ops); |
| 8075 |
Objects.requireNonNull(executor); |
| 8076 |
Objects.requireNonNull(callback); |
| 8077 |
IAppOpsActiveCallback cb; |
| 8078 |
synchronized (mActiveWatchers) { |
| 8079 |
cb = mActiveWatchers.get(callback); |
| 8080 |
if (cb != null) { |
| 8081 |
return; |
| 8082 |
} |
| 8083 |
cb = new IAppOpsActiveCallback.Stub() { |
| 8084 |
@Override |
| 8085 |
public void opActiveChanged(int op, int uid, String packageName, |
| 8086 |
String attributionTag, boolean active, @AttributionFlags |
| 8087 |
int attributionFlags, int attributionChainId) { |
| 8088 |
executor.execute(() -> { |
| 8089 |
if (callback instanceof OnOpActiveChangedInternalListener) { |
| 8090 |
((OnOpActiveChangedInternalListener) callback).onOpActiveChanged(op, |
| 8091 |
uid, packageName, active); |
| 8092 |
} |
| 8093 |
if (sOpToString[op] != null) { |
| 8094 |
callback.onOpActiveChanged(sOpToString[op], uid, packageName, |
| 8095 |
attributionTag, active, attributionFlags, attributionChainId); |
| 8096 |
} |
| 8097 |
}); |
| 8098 |
} |
| 8099 |
}; |
| 8100 |
mActiveWatchers.put(callback, cb); |
| 8101 |
} |
| 8102 |
final int[] rawOps = new int[ops.length]; |
| 8103 |
for (int i = 0; i < ops.length; i++) { |
| 8104 |
rawOps[i] = strOpToOp(ops[i]); |
| 8105 |
} |
| 8106 |
try { |
| 8107 |
mService.startWatchingActive(rawOps, cb); |
| 8108 |
} catch (RemoteException e) { |
| 8109 |
throw e.rethrowFromSystemServer(); |
| 8110 |
} |
| 8111 |
} |
| 8112 |
|
| 8113 |
|
| 8114 |
|
| 8115 |
|
| 8116 |
|
| 8117 |
|
| 8118 |
|
| 8119 |
|
| 8120 |
public void stopWatchingActive(@NonNull OnOpActiveChangedListener callback) { |
| 8121 |
synchronized (mActiveWatchers) { |
| 8122 |
final IAppOpsActiveCallback cb = mActiveWatchers.remove(callback); |
| 8123 |
if (cb != null) { |
| 8124 |
try { |
| 8125 |
mService.stopWatchingActive(cb); |
| 8126 |
} catch (RemoteException e) { |
| 8127 |
throw e.rethrowFromSystemServer(); |
| 8128 |
} |
| 8129 |
} |
| 8130 |
} |
| 8131 |
} |
| 8132 |
|
| 8133 |
|
| 8134 |
|
| 8135 |
|
| 8136 |
|
| 8137 |
|
| 8138 |
|
| 8139 |
|
| 8140 |
|
| 8141 |
|
| 8142 |
|
| 8143 |
|
| 8144 |
|
| 8145 |
|
| 8146 |
|
| 8147 |
|
| 8148 |
|
| 8149 |
|
| 8150 |
|
| 8151 |
|
| 8152 |
|
| 8153 |
|
| 8154 |
@RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true) |
| 8155 |
public void startWatchingStarted(@NonNull int[] ops, @NonNull OnOpStartedListener callback) { |
| 8156 |
IAppOpsStartedCallback cb; |
| 8157 |
synchronized (mStartedWatchers) { |
| 8158 |
if (mStartedWatchers.containsKey(callback)) { |
| 8159 |
return; |
| 8160 |
} |
| 8161 |
cb = new IAppOpsStartedCallback.Stub() { |
| 8162 |
@Override |
| 8163 |
public void opStarted(int op, int uid, String packageName, String attributionTag, |
| 8164 |
int flags, int mode, int startType, int attributionFlags, |
| 8165 |
int attributionChainId) { |
| 8166 |
callback.onOpStarted(op, uid, packageName, attributionTag, flags, mode, |
| 8167 |
startType, attributionFlags, attributionChainId); |
| 8168 |
} |
| 8169 |
}; |
| 8170 |
mStartedWatchers.put(callback, cb); |
| 8171 |
} |
| 8172 |
try { |
| 8173 |
mService.startWatchingStarted(ops, cb); |
| 8174 |
} catch (RemoteException e) { |
| 8175 |
throw e.rethrowFromSystemServer(); |
| 8176 |
} |
| 8177 |
} |
| 8178 |
|
| 8179 |
|
| 8180 |
|
| 8181 |
|
| 8182 |
|
| 8183 |
|
| 8184 |
|
| 8185 |
|
| 8186 |
|
| 8187 |
|
| 8188 |
|
| 8189 |
|
| 8190 |
public void stopWatchingStarted(@NonNull OnOpStartedListener callback) { |
| 8191 |
synchronized (mStartedWatchers) { |
| 8192 |
final IAppOpsStartedCallback cb = mStartedWatchers.remove(callback); |
| 8193 |
if (cb != null) { |
| 8194 |
try { |
| 8195 |
mService.stopWatchingStarted(cb); |
| 8196 |
} catch (RemoteException e) { |
| 8197 |
throw e.rethrowFromSystemServer(); |
| 8198 |
} |
| 8199 |
} |
| 8200 |
} |
| 8201 |
} |
| 8202 |
|
| 8203 |
|
| 8204 |
|
| 8205 |
|
| 8206 |
|
| 8207 |
|
| 8208 |
|
| 8209 |
|
| 8210 |
|
| 8211 |
|
| 8212 |
|
| 8213 |
|
| 8214 |
|
| 8215 |
|
| 8216 |
|
| 8217 |
|
| 8218 |
|
| 8219 |
|
| 8220 |
|
| 8221 |
|
| 8222 |
|
| 8223 |
@RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true) |
| 8224 |
public void startWatchingNoted(@NonNull int[] ops, @NonNull OnOpNotedListener callback) { |
| 8225 |
IAppOpsNotedCallback cb; |
| 8226 |
synchronized (mNotedWatchers) { |
| 8227 |
cb = mNotedWatchers.get(callback); |
| 8228 |
if (cb != null) { |
| 8229 |
return; |
| 8230 |
} |
| 8231 |
cb = new IAppOpsNotedCallback.Stub() { |
| 8232 |
@Override |
| 8233 |
public void opNoted(int op, int uid, String packageName, String attributionTag, |
| 8234 |
int flags, int mode) { |
| 8235 |
callback.onOpNoted(op, uid, packageName, attributionTag, flags, mode); |
| 8236 |
} |
| 8237 |
}; |
| 8238 |
mNotedWatchers.put(callback, cb); |
| 8239 |
} |
| 8240 |
try { |
| 8241 |
mService.startWatchingNoted(ops, cb); |
| 8242 |
} catch (RemoteException e) { |
| 8243 |
throw e.rethrowFromSystemServer(); |
| 8244 |
} |
| 8245 |
} |
| 8246 |
|
| 8247 |
|
| 8248 |
|
| 8249 |
|
| 8250 |
|
| 8251 |
|
| 8252 |
|
| 8253 |
|
| 8254 |
|
| 8255 |
|
| 8256 |
public void stopWatchingNoted(@NonNull OnOpNotedListener callback) { |
| 8257 |
synchronized (mNotedWatchers) { |
| 8258 |
final IAppOpsNotedCallback cb = mNotedWatchers.remove(callback); |
| 8259 |
if (cb != null) { |
| 8260 |
try { |
| 8261 |
mService.stopWatchingNoted(cb); |
| 8262 |
} catch (RemoteException e) { |
| 8263 |
throw e.rethrowFromSystemServer(); |
| 8264 |
} |
| 8265 |
} |
| 8266 |
} |
| 8267 |
} |
| 8268 |
|
| 8269 |
private String buildSecurityExceptionMsg(int op, int uid, String packageName) { |
| 8270 |
return packageName + " from uid " + uid + " not allowed to perform " + sOpNames[op]; |
| 8271 |
} |
| 8272 |
|
| 8273 |
|
| 8274 |
|
| 8275 |
|
| 8276 |
@UnsupportedAppUsage |
| 8277 |
@TestApi |
| 8278 |
public static int strOpToOp(@NonNull String op) { |
| 8279 |
Integer val = sOpStrToOp.get(op); |
| 8280 |
if (val == null) { |
| 8281 |
throw new IllegalArgumentException("Unknown operation string: " + op); |
| 8282 |
} |
| 8283 |
return val; |
| 8284 |
} |
| 8285 |
|
| 8286 |
|
| 8287 |
|
| 8288 |
|
| 8289 |
|
| 8290 |
|
| 8291 |
|
| 8292 |
|
| 8293 |
|
| 8294 |
|
| 8295 |
|
| 8296 |
|
| 8297 |
|
| 8298 |
|
| 8299 |
|
| 8300 |
|
| 8301 |
|
| 8302 |
|
| 8303 |
|
| 8304 |
|
| 8305 |
|
| 8306 |
|
| 8307 |
|
| 8308 |
|
| 8309 |
|
| 8310 |
|
| 8311 |
|
| 8312 |
|
| 8313 |
|
| 8314 |
public int unsafeCheckOp(@NonNull String op, int uid, @NonNull String packageName) { |
| 8315 |
return checkOp(strOpToOp(op), uid, packageName); |
| 8316 |
} |
| 8317 |
|
| 8318 |
|
| 8319 |
|
| 8320 |
|
| 8321 |
@Deprecated |
| 8322 |
public int checkOp(@NonNull String op, int uid, @NonNull String packageName) { |
| 8323 |
return checkOp(strOpToOp(op), uid, packageName); |
| 8324 |
} |
| 8325 |
|
| 8326 |
|
| 8327 |
|
| 8328 |
|
| 8329 |
|
| 8330 |
public int unsafeCheckOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
| 8331 |
return checkOpNoThrow(strOpToOp(op), uid, packageName); |
| 8332 |
} |
| 8333 |
|
| 8334 |
|
| 8335 |
|
| 8336 |
|
| 8337 |
@Deprecated |
| 8338 |
public int checkOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
| 8339 |
return checkOpNoThrow(strOpToOp(op), uid, packageName); |
| 8340 |
} |
| 8341 |
|
| 8342 |
|
| 8343 |
|
| 8344 |
|
| 8345 |
|
| 8346 |
public int unsafeCheckOpRaw(@NonNull String op, int uid, @NonNull String packageName) { |
| 8347 |
return unsafeCheckOpRawNoThrow(op, uid, packageName); |
| 8348 |
} |
| 8349 |
|
| 8350 |
|
| 8351 |
|
| 8352 |
|
| 8353 |
|
| 8354 |
|
| 8355 |
public int unsafeCheckOpRawNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
| 8356 |
return unsafeCheckOpRawNoThrow(strOpToOp(op), uid, packageName); |
| 8357 |
} |
| 8358 |
|
| 8359 |
|
| 8360 |
|
| 8361 |
|
| 8362 |
|
| 8363 |
|
| 8364 |
public int unsafeCheckOpRawNoThrow(int op, int uid, @NonNull String packageName) { |
| 8365 |
try { |
| 8366 |
return mService.checkOperationRaw(op, uid, packageName, null); |
| 8367 |
} catch (RemoteException e) { |
| 8368 |
throw e.rethrowFromSystemServer(); |
| 8369 |
} |
| 8370 |
} |
| 8371 |
|
| 8372 |
|
| 8373 |
|
| 8374 |
|
| 8375 |
@Deprecated |
| 8376 |
public int noteOp(@NonNull String op, int uid, @NonNull String packageName) { |
| 8377 |
return noteOp(op, uid, packageName, null, null); |
| 8378 |
} |
| 8379 |
|
| 8380 |
|
| 8381 |
|
| 8382 |
|
| 8383 |
|
| 8384 |
|
| 8385 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " |
| 8386 |
+ "#noteOp(java.lang.String, int, java.lang.String, java.lang.String, " |
| 8387 |
+ "java.lang.String)} instead") |
| 8388 |
@Deprecated |
| 8389 |
public int noteOp(int op) { |
| 8390 |
return noteOp(op, Process.myUid(), mContext.getOpPackageName(), null, null); |
| 8391 |
} |
| 8392 |
|
| 8393 |
|
| 8394 |
|
| 8395 |
|
| 8396 |
|
| 8397 |
|
| 8398 |
@Deprecated |
| 8399 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " |
| 8400 |
+ "#noteOp(java.lang.String, int, java.lang.String, java.lang.String, " |
| 8401 |
+ "java.lang.String)} instead") |
| 8402 |
public int noteOp(int op, int uid, @Nullable String packageName) { |
| 8403 |
return noteOp(op, uid, packageName, null, null); |
| 8404 |
} |
| 8405 |
|
| 8406 |
|
| 8407 |
|
| 8408 |
|
| 8409 |
|
| 8410 |
|
| 8411 |
|
| 8412 |
|
| 8413 |
|
| 8414 |
|
| 8415 |
|
| 8416 |
|
| 8417 |
|
| 8418 |
|
| 8419 |
|
| 8420 |
|
| 8421 |
|
| 8422 |
|
| 8423 |
|
| 8424 |
|
| 8425 |
|
| 8426 |
|
| 8427 |
|
| 8428 |
|
| 8429 |
|
| 8430 |
|
| 8431 |
|
| 8432 |
|
| 8433 |
|
| 8434 |
|
| 8435 |
|
| 8436 |
|
| 8437 |
|
| 8438 |
|
| 8439 |
|
| 8440 |
|
| 8441 |
|
| 8442 |
|
| 8443 |
|
| 8444 |
|
| 8445 |
|
| 8446 |
|
| 8447 |
|
| 8448 |
|
| 8449 |
|
| 8450 |
|
| 8451 |
|
| 8452 |
|
| 8453 |
|
| 8454 |
|
| 8455 |
|
| 8456 |
|
| 8457 |
|
| 8458 |
|
| 8459 |
public int noteOp(@NonNull String op, int uid, @Nullable String packageName, |
| 8460 |
@Nullable String attributionTag, @Nullable String message) { |
| 8461 |
return noteOp(strOpToOp(op), uid, packageName, attributionTag, message); |
| 8462 |
} |
| 8463 |
|
| 8464 |
|
| 8465 |
|
| 8466 |
|
| 8467 |
|
| 8468 |
|
| 8469 |
public int noteOp(int op, int uid, @Nullable String packageName, |
| 8470 |
@Nullable String attributionTag, @Nullable String message) { |
| 8471 |
final int mode = noteOpNoThrow(op, uid, packageName, attributionTag, message); |
| 8472 |
if (mode == MODE_ERRORED) { |
| 8473 |
throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
| 8474 |
} |
| 8475 |
return mode; |
| 8476 |
} |
| 8477 |
|
| 8478 |
|
| 8479 |
|
| 8480 |
|
| 8481 |
@Deprecated |
| 8482 |
public int noteOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
| 8483 |
return noteOpNoThrow(op, uid, packageName, null, null); |
| 8484 |
} |
| 8485 |
|
| 8486 |
|
| 8487 |
|
| 8488 |
|
| 8489 |
|
| 8490 |
|
| 8491 |
@Deprecated |
| 8492 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " |
| 8493 |
+ "#noteOpNoThrow(java.lang.String, int, java.lang.String, java.lang.String, " |
| 8494 |
+ "java.lang.String)} instead") |
| 8495 |
public int noteOpNoThrow(int op, int uid, String packageName) { |
| 8496 |
return noteOpNoThrow(op, uid, packageName, null, null); |
| 8497 |
} |
| 8498 |
|
| 8499 |
|
| 8500 |
|
| 8501 |
|
| 8502 |
|
| 8503 |
|
| 8504 |
|
| 8505 |
public int noteOpNoThrow(@NonNull String op, int uid, @NonNull String packageName, |
| 8506 |
@Nullable String attributionTag, @Nullable String message) { |
| 8507 |
return noteOpNoThrow(strOpToOp(op), uid, packageName, attributionTag, message); |
| 8508 |
} |
| 8509 |
|
| 8510 |
|
| 8511 |
|
| 8512 |
|
| 8513 |
|
| 8514 |
|
| 8515 |
public int noteOpNoThrow(int op, int uid, @Nullable String packageName, |
| 8516 |
@Nullable String attributionTag, @Nullable String message) { |
| 8517 |
try { |
| 8518 |
collectNoteOpCallsForValidation(op); |
| 8519 |
int collectionMode = getNotedOpCollectionMode(uid, packageName, op); |
| 8520 |
boolean shouldCollectMessage = Process.myUid() == Process.SYSTEM_UID; |
| 8521 |
if (collectionMode == COLLECT_ASYNC) { |
| 8522 |
if (message == null) { |
| 8523 |
|
| 8524 |
message = getFormattedStackTrace(); |
| 8525 |
shouldCollectMessage = true; |
| 8526 |
} |
| 8527 |
} |
| 8528 |
|
| 8529 |
SyncNotedAppOp syncOp = mService.noteOperation(op, uid, packageName, attributionTag, |
| 8530 |
collectionMode == COLLECT_ASYNC, message, shouldCollectMessage); |
| 8531 |
|
| 8532 |
if (syncOp.getOpMode() == MODE_ALLOWED) { |
| 8533 |
if (collectionMode == COLLECT_SELF) { |
| 8534 |
collectNotedOpForSelf(syncOp); |
| 8535 |
} else if (collectionMode == COLLECT_SYNC) { |
| 8536 |
collectNotedOpSync(syncOp); |
| 8537 |
} |
| 8538 |
} |
| 8539 |
|
| 8540 |
return syncOp.getOpMode(); |
| 8541 |
} catch (RemoteException e) { |
| 8542 |
throw e.rethrowFromSystemServer(); |
| 8543 |
} |
| 8544 |
} |
| 8545 |
|
| 8546 |
|
| 8547 |
|
| 8548 |
|
| 8549 |
@Deprecated |
| 8550 |
public int noteProxyOp(@NonNull String op, @NonNull String proxiedPackageName) { |
| 8551 |
return noteProxyOp(op, proxiedPackageName, Binder.getCallingUid(), null, null); |
| 8552 |
} |
| 8553 |
|
| 8554 |
|
| 8555 |
|
| 8556 |
|
| 8557 |
|
| 8558 |
|
| 8559 |
@Deprecated |
| 8560 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " |
| 8561 |
+ "#noteProxyOp(java.lang.String, java.lang.String, int, java.lang.String, " |
| 8562 |
+ "java.lang.String)} instead") |
| 8563 |
public int noteProxyOp(int op, @Nullable String proxiedPackageName) { |
| 8564 |
return noteProxyOp(op, proxiedPackageName, Binder.getCallingUid(), null, null); |
| 8565 |
} |
| 8566 |
|
| 8567 |
|
| 8568 |
|
| 8569 |
|
| 8570 |
|
| 8571 |
|
| 8572 |
public int noteProxyOp(int op, @Nullable String proxiedPackageName, int proxiedUid, |
| 8573 |
@Nullable String proxiedAttributionTag, @Nullable String message) { |
| 8574 |
return noteProxyOp(op, new AttributionSource(mContext.getAttributionSource(), |
| 8575 |
new AttributionSource(proxiedUid, proxiedPackageName, proxiedAttributionTag, |
| 8576 |
mContext.getAttributionSource().getToken())), message, |
| 8577 |
false); |
| 8578 |
} |
| 8579 |
|
| 8580 |
|
| 8581 |
|
| 8582 |
|
| 8583 |
|
| 8584 |
|
| 8585 |
|
| 8586 |
|
| 8587 |
|
| 8588 |
|
| 8589 |
|
| 8590 |
|
| 8591 |
|
| 8592 |
|
| 8593 |
|
| 8594 |
|
| 8595 |
|
| 8596 |
|
| 8597 |
|
| 8598 |
|
| 8599 |
public int noteProxyOp(@NonNull String op, @Nullable String proxiedPackageName, int proxiedUid, |
| 8600 |
@Nullable String proxiedAttributionTag, @Nullable String message) { |
| 8601 |
return noteProxyOp(strOpToOp(op), proxiedPackageName, proxiedUid, proxiedAttributionTag, |
| 8602 |
message); |
| 8603 |
} |
| 8604 |
|
| 8605 |
|
| 8606 |
|
| 8607 |
|
| 8608 |
|
| 8609 |
|
| 8610 |
|
| 8611 |
|
| 8612 |
|
| 8613 |
|
| 8614 |
|
| 8615 |
|
| 8616 |
|
| 8617 |
|
| 8618 |
|
| 8619 |
|
| 8620 |
|
| 8621 |
public int noteProxyOp(@NonNull int op, @NonNull AttributionSource attributionSource, |
| 8622 |
@Nullable String message, boolean skipProxyOperation) { |
| 8623 |
final int mode = noteProxyOpNoThrow(op, attributionSource, message, skipProxyOperation); |
| 8624 |
if (mode == MODE_ERRORED) { |
| 8625 |
throw new SecurityException("Proxy package " |
| 8626 |
+ attributionSource.getPackageName() + " from uid " |
| 8627 |
+ attributionSource.getUid() + " or calling package " |
| 8628 |
+ attributionSource.getNextPackageName() + " from uid " |
| 8629 |
+ attributionSource.getNextUid() + " not allowed to perform " |
| 8630 |
+ sOpNames[op]); |
| 8631 |
} |
| 8632 |
return mode; |
| 8633 |
} |
| 8634 |
|
| 8635 |
|
| 8636 |
|
| 8637 |
|
| 8638 |
@Deprecated |
| 8639 |
public int noteProxyOpNoThrow(@NonNull String op, @NonNull String proxiedPackageName) { |
| 8640 |
return noteProxyOpNoThrow(op, proxiedPackageName, Binder.getCallingUid(), null, null); |
| 8641 |
} |
| 8642 |
|
| 8643 |
|
| 8644 |
|
| 8645 |
|
| 8646 |
@Deprecated |
| 8647 |
public int noteProxyOpNoThrow(@NonNull String op, @Nullable String proxiedPackageName, |
| 8648 |
int proxiedUid) { |
| 8649 |
return noteProxyOpNoThrow(op, proxiedPackageName, proxiedUid, null, null); |
| 8650 |
} |
| 8651 |
|
| 8652 |
|
| 8653 |
|
| 8654 |
|
| 8655 |
|
| 8656 |
|
| 8657 |
|
| 8658 |
public int noteProxyOpNoThrow(@NonNull String op, @Nullable String proxiedPackageName, |
| 8659 |
int proxiedUid, @Nullable String proxiedAttributionTag, @Nullable String message) { |
| 8660 |
return noteProxyOpNoThrow(strOpToOp(op), new AttributionSource( |
| 8661 |
mContext.getAttributionSource(), new AttributionSource(proxiedUid, |
| 8662 |
proxiedPackageName, proxiedAttributionTag, mContext.getAttributionSource() |
| 8663 |
.getToken())), message, false); |
| 8664 |
} |
| 8665 |
|
| 8666 |
|
| 8667 |
|
| 8668 |
|
| 8669 |
|
| 8670 |
|
| 8671 |
|
| 8672 |
|
| 8673 |
|
| 8674 |
|
| 8675 |
|
| 8676 |
|
| 8677 |
|
| 8678 |
|
| 8679 |
@SuppressWarnings("AndroidFrameworkClientSidePermissionCheck") |
| 8680 |
public int noteProxyOpNoThrow(int op, @NonNull AttributionSource attributionSource, |
| 8681 |
@Nullable String message, boolean skipProxyOperation) { |
| 8682 |
int myUid = Process.myUid(); |
| 8683 |
|
| 8684 |
try { |
| 8685 |
collectNoteOpCallsForValidation(op); |
| 8686 |
int collectionMode = getNotedOpCollectionMode( |
| 8687 |
attributionSource.getNextUid(), |
| 8688 |
attributionSource.getNextAttributionTag(), op); |
| 8689 |
boolean shouldCollectMessage = (myUid == Process.SYSTEM_UID); |
| 8690 |
if (collectionMode == COLLECT_ASYNC) { |
| 8691 |
if (message == null) { |
| 8692 |
|
| 8693 |
message = getFormattedStackTrace(); |
| 8694 |
shouldCollectMessage = true; |
| 8695 |
} |
| 8696 |
} |
| 8697 |
|
| 8698 |
SyncNotedAppOp syncOp = mService.noteProxyOperation(op, attributionSource, |
| 8699 |
collectionMode == COLLECT_ASYNC, message, |
| 8700 |
shouldCollectMessage, skipProxyOperation); |
| 8701 |
|
| 8702 |
if (syncOp.getOpMode() == MODE_ALLOWED) { |
| 8703 |
if (collectionMode == COLLECT_SELF) { |
| 8704 |
collectNotedOpForSelf(syncOp); |
| 8705 |
} else if (collectionMode == COLLECT_SYNC |
| 8706 |
|
| 8707 |
&& (mContext.checkPermission(Manifest.permission.UPDATE_APP_OPS_STATS, -1, |
| 8708 |
myUid) == PackageManager.PERMISSION_GRANTED || |
| 8709 |
Binder.getCallingUid() == attributionSource.getNextUid())) { |
| 8710 |
collectNotedOpSync(syncOp); |
| 8711 |
} |
| 8712 |
} |
| 8713 |
|
| 8714 |
return syncOp.getOpMode(); |
| 8715 |
} catch (RemoteException e) { |
| 8716 |
throw e.rethrowFromSystemServer(); |
| 8717 |
} |
| 8718 |
} |
| 8719 |
|
| 8720 |
private static String getComponentPackageNameFromString(String from) { |
| 8721 |
ComponentName componentName = from != null ? ComponentName.unflattenFromString(from) : null; |
| 8722 |
return componentName != null ? componentName.getPackageName() : ""; |
| 8723 |
} |
| 8724 |
|
| 8725 |
private static boolean isPackagePreInstalled(Context context, String packageName, int userId) { |
| 8726 |
try { |
| 8727 |
final PackageManager pm = context.getPackageManager(); |
| 8728 |
final ApplicationInfo info = |
| 8729 |
pm.getApplicationInfoAsUser(packageName, 0, userId); |
| 8730 |
return ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0); |
| 8731 |
} catch (PackageManager.NameNotFoundException e) { |
| 8732 |
return false; |
| 8733 |
} |
| 8734 |
} |
| 8735 |
|
| 8736 |
|
| 8737 |
|
| 8738 |
|
| 8739 |
|
| 8740 |
|
| 8741 |
|
| 8742 |
|
| 8743 |
|
| 8744 |
|
| 8745 |
|
| 8746 |
|
| 8747 |
|
| 8748 |
|
| 8749 |
|
| 8750 |
|
| 8751 |
|
| 8752 |
|
| 8753 |
|
| 8754 |
|
| 8755 |
|
| 8756 |
|
| 8757 |
|
| 8758 |
|
| 8759 |
|
| 8760 |
|
| 8761 |
|
| 8762 |
|
| 8763 |
|
| 8764 |
|
| 8765 |
@UnsupportedAppUsage |
| 8766 |
public int checkOp(int op, int uid, String packageName) { |
| 8767 |
try { |
| 8768 |
int mode = mService.checkOperation(op, uid, packageName); |
| 8769 |
if (mode == MODE_ERRORED) { |
| 8770 |
throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
| 8771 |
} |
| 8772 |
return mode; |
| 8773 |
} catch (RemoteException e) { |
| 8774 |
throw e.rethrowFromSystemServer(); |
| 8775 |
} |
| 8776 |
} |
| 8777 |
|
| 8778 |
|
| 8779 |
|
| 8780 |
|
| 8781 |
|
| 8782 |
|
| 8783 |
|
| 8784 |
|
| 8785 |
|
| 8786 |
@UnsupportedAppUsage |
| 8787 |
public int checkOpNoThrow(int op, int uid, String packageName) { |
| 8788 |
try { |
| 8789 |
int mode = mService.checkOperation(op, uid, packageName); |
| 8790 |
return mode == AppOpsManager.MODE_FOREGROUND ? AppOpsManager.MODE_ALLOWED : mode; |
| 8791 |
} catch (RemoteException e) { |
| 8792 |
throw e.rethrowFromSystemServer(); |
| 8793 |
} |
| 8794 |
} |
| 8795 |
|
| 8796 |
|
| 8797 |
|
| 8798 |
|
| 8799 |
@Deprecated |
| 8800 |
public void checkPackage(int uid, @NonNull String packageName) { |
| 8801 |
try { |
| 8802 |
if (mService.checkPackage(uid, packageName) != MODE_ALLOWED) { |
| 8803 |
throw new SecurityException( |
| 8804 |
"Package " + packageName + " does not belong to " + uid); |
| 8805 |
} |
| 8806 |
} catch (RemoteException e) { |
| 8807 |
throw e.rethrowFromSystemServer(); |
| 8808 |
} |
| 8809 |
} |
| 8810 |
|
| 8811 |
|
| 8812 |
|
| 8813 |
|
| 8814 |
|
| 8815 |
public int checkAudioOp(int op, int stream, int uid, String packageName) { |
| 8816 |
try { |
| 8817 |
final int mode = mService.checkAudioOperation(op, stream, uid, packageName); |
| 8818 |
if (mode == MODE_ERRORED) { |
| 8819 |
throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
| 8820 |
} |
| 8821 |
return mode; |
| 8822 |
} catch (RemoteException e) { |
| 8823 |
throw e.rethrowFromSystemServer(); |
| 8824 |
} |
| 8825 |
} |
| 8826 |
|
| 8827 |
|
| 8828 |
|
| 8829 |
|
| 8830 |
|
| 8831 |
|
| 8832 |
public int checkAudioOpNoThrow(int op, int stream, int uid, String packageName) { |
| 8833 |
try { |
| 8834 |
return mService.checkAudioOperation(op, stream, uid, packageName); |
| 8835 |
} catch (RemoteException e) { |
| 8836 |
throw e.rethrowFromSystemServer(); |
| 8837 |
} |
| 8838 |
} |
| 8839 |
|
| 8840 |
|
| 8841 |
|
| 8842 |
|
| 8843 |
|
| 8844 |
|
| 8845 |
@Deprecated |
| 8846 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Create own " |
| 8847 |
+ "local {@link android.os.Binder}") |
| 8848 |
public static IBinder getToken(IAppOpsService service) { |
| 8849 |
return getClientId(); |
| 8850 |
} |
| 8851 |
|
| 8852 |
|
| 8853 |
public static IBinder getClientId() { |
| 8854 |
synchronized (AppOpsManager.class) { |
| 8855 |
if (sClientId == null) { |
| 8856 |
sClientId = new Binder(); |
| 8857 |
} |
| 8858 |
|
| 8859 |
return sClientId; |
| 8860 |
} |
| 8861 |
} |
| 8862 |
|
| 8863 |
|
| 8864 |
private static IAppOpsService getService() { |
| 8865 |
synchronized (sLock) { |
| 8866 |
if (sService == null) { |
| 8867 |
sService = IAppOpsService.Stub.asInterface( |
| 8868 |
ServiceManager.getService(Context.APP_OPS_SERVICE)); |
| 8869 |
} |
| 8870 |
return sService; |
| 8871 |
} |
| 8872 |
} |
| 8873 |
|
| 8874 |
|
| 8875 |
|
| 8876 |
|
| 8877 |
@Deprecated |
| 8878 |
public int startOp(@NonNull String op, int uid, @NonNull String packageName) { |
| 8879 |
return startOp(op, uid, packageName, null, null); |
| 8880 |
} |
| 8881 |
|
| 8882 |
|
| 8883 |
|
| 8884 |
|
| 8885 |
|
| 8886 |
|
| 8887 |
@Deprecated |
| 8888 |
public int startOp(int op) { |
| 8889 |
return startOp(op, Process.myUid(), mContext.getOpPackageName(), false, null, null); |
| 8890 |
} |
| 8891 |
|
| 8892 |
|
| 8893 |
|
| 8894 |
|
| 8895 |
|
| 8896 |
|
| 8897 |
@Deprecated |
| 8898 |
public int startOp(int op, int uid, String packageName) { |
| 8899 |
return startOp(op, uid, packageName, false, null, null); |
| 8900 |
} |
| 8901 |
|
| 8902 |
|
| 8903 |
|
| 8904 |
|
| 8905 |
|
| 8906 |
|
| 8907 |
@Deprecated |
| 8908 |
public int startOp(int op, int uid, String packageName, boolean startIfModeDefault) { |
| 8909 |
return startOp(op, uid, packageName, startIfModeDefault, null, null); |
| 8910 |
} |
| 8911 |
|
| 8912 |
|
| 8913 |
|
| 8914 |
|
| 8915 |
|
| 8916 |
|
| 8917 |
|
| 8918 |
|
| 8919 |
|
| 8920 |
|
| 8921 |
|
| 8922 |
|
| 8923 |
|
| 8924 |
|
| 8925 |
|
| 8926 |
|
| 8927 |
|
| 8928 |
|
| 8929 |
|
| 8930 |
|
| 8931 |
|
| 8932 |
|
| 8933 |
public int startOp(@NonNull String op, int uid, @Nullable String packageName, |
| 8934 |
@Nullable String attributionTag, @Nullable String message) { |
| 8935 |
return startOp(strOpToOp(op), uid, packageName, false, attributionTag, message); |
| 8936 |
} |
| 8937 |
|
| 8938 |
|
| 8939 |
|
| 8940 |
|
| 8941 |
|
| 8942 |
|
| 8943 |
public int startOp(int op, int uid, @Nullable String packageName, boolean startIfModeDefault, |
| 8944 |
@Nullable String attributionTag, @Nullable String message) { |
| 8945 |
final int mode = startOpNoThrow(op, uid, packageName, startIfModeDefault, attributionTag, |
| 8946 |
message); |
| 8947 |
if (mode == MODE_ERRORED) { |
| 8948 |
throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
| 8949 |
} |
| 8950 |
return mode; |
| 8951 |
} |
| 8952 |
|
| 8953 |
|
| 8954 |
|
| 8955 |
|
| 8956 |
@Deprecated |
| 8957 |
public int startOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) { |
| 8958 |
return startOpNoThrow(op, uid, packageName, null, null); |
| 8959 |
} |
| 8960 |
|
| 8961 |
|
| 8962 |
|
| 8963 |
|
| 8964 |
|
| 8965 |
|
| 8966 |
@Deprecated |
| 8967 |
public int startOpNoThrow(int op, int uid, String packageName) { |
| 8968 |
return startOpNoThrow(op, uid, packageName, false, null, null); |
| 8969 |
} |
| 8970 |
|
| 8971 |
|
| 8972 |
|
| 8973 |
|
| 8974 |
|
| 8975 |
|
| 8976 |
@Deprecated |
| 8977 |
public int startOpNoThrow(int op, int uid, String packageName, boolean startIfModeDefault) { |
| 8978 |
return startOpNoThrow(op, uid, packageName, startIfModeDefault, null, null); |
| 8979 |
} |
| 8980 |
|
| 8981 |
|
| 8982 |
|
| 8983 |
|
| 8984 |
|
| 8985 |
|
| 8986 |
|
| 8987 |
public int startOpNoThrow(@NonNull String op, int uid, @NonNull String packageName, |
| 8988 |
@NonNull String attributionTag, @Nullable String message) { |
| 8989 |
return startOpNoThrow(strOpToOp(op), uid, packageName, false, attributionTag, message); |
| 8990 |
} |
| 8991 |
|
| 8992 |
|
| 8993 |
|
| 8994 |
|
| 8995 |
|
| 8996 |
|
| 8997 |
public int startOpNoThrow(int op, int uid, @NonNull String packageName, |
| 8998 |
boolean startIfModeDefault, @Nullable String attributionTag, @Nullable String message) { |
| 8999 |
return startOpNoThrow(mContext.getAttributionSource().getToken(), op, uid, packageName, |
| 9000 |
startIfModeDefault, attributionTag, message); |
| 9001 |
} |
| 9002 |
|
| 9003 |
|
| 9004 |
|
| 9005 |
|
| 9006 |
|
| 9007 |
|
| 9008 |
public int startOpNoThrow(@NonNull IBinder token, int op, int uid, @NonNull String packageName, |
| 9009 |
boolean startIfModeDefault, @Nullable String attributionTag, @Nullable String message) { |
| 9010 |
return startOpNoThrow(token, op, uid, packageName, startIfModeDefault, attributionTag, |
| 9011 |
message, ATTRIBUTION_FLAGS_NONE, ATTRIBUTION_CHAIN_ID_NONE); |
| 9012 |
} |
| 9013 |
|
| 9014 |
|
| 9015 |
|
| 9016 |
|
| 9017 |
|
| 9018 |
|
| 9019 |
public int startOpNoThrow(@NonNull IBinder token, int op, int uid, @NonNull String packageName, |
| 9020 |
boolean startIfModeDefault, @Nullable String attributionTag, @Nullable String message, |
| 9021 |
@AttributionFlags int attributionFlags, int attributionChainId) { |
| 9022 |
try { |
| 9023 |
collectNoteOpCallsForValidation(op); |
| 9024 |
int collectionMode = getNotedOpCollectionMode(uid, packageName, op); |
| 9025 |
boolean shouldCollectMessage = Process.myUid() == Process.SYSTEM_UID; |
| 9026 |
if (collectionMode == COLLECT_ASYNC) { |
| 9027 |
if (message == null) { |
| 9028 |
|
| 9029 |
message = getFormattedStackTrace(); |
| 9030 |
shouldCollectMessage = true; |
| 9031 |
} |
| 9032 |
} |
| 9033 |
|
| 9034 |
SyncNotedAppOp syncOp = mService.startOperation(token, op, uid, packageName, |
| 9035 |
attributionTag, startIfModeDefault, collectionMode == COLLECT_ASYNC, message, |
| 9036 |
shouldCollectMessage, attributionFlags, attributionChainId); |
| 9037 |
|
| 9038 |
if (syncOp.getOpMode() == MODE_ALLOWED) { |
| 9039 |
if (collectionMode == COLLECT_SELF) { |
| 9040 |
collectNotedOpForSelf(syncOp); |
| 9041 |
} else if (collectionMode == COLLECT_SYNC) { |
| 9042 |
collectNotedOpSync(syncOp); |
| 9043 |
} |
| 9044 |
} |
| 9045 |
|
| 9046 |
return syncOp.getOpMode(); |
| 9047 |
} catch (RemoteException e) { |
| 9048 |
throw e.rethrowFromSystemServer(); |
| 9049 |
} |
| 9050 |
} |
| 9051 |
|
| 9052 |
|
| 9053 |
|
| 9054 |
|
| 9055 |
|
| 9056 |
|
| 9057 |
|
| 9058 |
|
| 9059 |
|
| 9060 |
|
| 9061 |
|
| 9062 |
|
| 9063 |
|
| 9064 |
|
| 9065 |
|
| 9066 |
|
| 9067 |
|
| 9068 |
|
| 9069 |
|
| 9070 |
public int startProxyOp(@NonNull String op, int proxiedUid, @NonNull String proxiedPackageName, |
| 9071 |
@Nullable String proxiedAttributionTag, @Nullable String message) { |
| 9072 |
return startProxyOp(op, new AttributionSource(mContext.getAttributionSource(), |
| 9073 |
new AttributionSource(proxiedUid, proxiedPackageName, proxiedAttributionTag, |
| 9074 |
mContext.getAttributionSource().getToken())), message, |
| 9075 |
false); |
| 9076 |
} |
| 9077 |
|
| 9078 |
|
| 9079 |
|
| 9080 |
|
| 9081 |
|
| 9082 |
|
| 9083 |
|
| 9084 |
|
| 9085 |
|
| 9086 |
|
| 9087 |
|
| 9088 |
|
| 9089 |
|
| 9090 |
|
| 9091 |
|
| 9092 |
|
| 9093 |
|
| 9094 |
|
| 9095 |
public int startProxyOp(@NonNull String op, @NonNull AttributionSource attributionSource, |
| 9096 |
@Nullable String message, boolean skipProxyOperation) { |
| 9097 |
final int mode = startProxyOpNoThrow(AppOpsManager.strOpToOp(op), attributionSource, |
| 9098 |
message, skipProxyOperation); |
| 9099 |
if (mode == MODE_ERRORED) { |
| 9100 |
throw new SecurityException("Proxy package " |
| 9101 |
+ attributionSource.getPackageName() + " from uid " |
| 9102 |
+ attributionSource.getUid() + " or calling package " |
| 9103 |
+ attributionSource.getNextPackageName() + " from uid " |
| 9104 |
+ attributionSource.getNextUid() + " not allowed to perform " |
| 9105 |
+ op); |
| 9106 |
} |
| 9107 |
return mode; |
| 9108 |
} |
| 9109 |
|
| 9110 |
|
| 9111 |
|
| 9112 |
|
| 9113 |
|
| 9114 |
|
| 9115 |
|
| 9116 |
public int startProxyOpNoThrow(@NonNull String op, int proxiedUid, |
| 9117 |
@NonNull String proxiedPackageName, @Nullable String proxiedAttributionTag, |
| 9118 |
@Nullable String message) { |
| 9119 |
return startProxyOpNoThrow(AppOpsManager.strOpToOp(op), new AttributionSource( |
| 9120 |
mContext.getAttributionSource(), new AttributionSource(proxiedUid, |
| 9121 |
proxiedPackageName, proxiedAttributionTag, |
| 9122 |
mContext.getAttributionSource().getToken())), message, |
| 9123 |
false); |
| 9124 |
} |
| 9125 |
|
| 9126 |
|
| 9127 |
|
| 9128 |
|
| 9129 |
|
| 9130 |
|
| 9131 |
|
| 9132 |
|
| 9133 |
|
| 9134 |
|
| 9135 |
public int startProxyOpNoThrow(int op, @NonNull AttributionSource attributionSource, |
| 9136 |
@Nullable String message, boolean skipProxyOperation) { |
| 9137 |
return startProxyOpNoThrow(attributionSource.getToken(), op, attributionSource, message, |
| 9138 |
skipProxyOperation, ATTRIBUTION_FLAGS_NONE, ATTRIBUTION_FLAGS_NONE, |
| 9139 |
ATTRIBUTION_CHAIN_ID_NONE); |
| 9140 |
} |
| 9141 |
|
| 9142 |
|
| 9143 |
|
| 9144 |
|
| 9145 |
|
| 9146 |
|
| 9147 |
|
| 9148 |
|
| 9149 |
|
| 9150 |
|
| 9151 |
public int startProxyOpNoThrow(@NonNull IBinder clientId, int op, |
| 9152 |
@NonNull AttributionSource attributionSource, |
| 9153 |
@Nullable String message, boolean skipProxyOperation, @AttributionFlags |
| 9154 |
int proxyAttributionFlags, @AttributionFlags int proxiedAttributionFlags, |
| 9155 |
int attributionChainId) { |
| 9156 |
try { |
| 9157 |
collectNoteOpCallsForValidation(op); |
| 9158 |
int collectionMode = getNotedOpCollectionMode( |
| 9159 |
attributionSource.getNextUid(), |
| 9160 |
attributionSource.getNextPackageName(), op); |
| 9161 |
boolean shouldCollectMessage = Process.myUid() == Process.SYSTEM_UID; |
| 9162 |
if (collectionMode == COLLECT_ASYNC) { |
| 9163 |
if (message == null) { |
| 9164 |
|
| 9165 |
message = getFormattedStackTrace(); |
| 9166 |
shouldCollectMessage = true; |
| 9167 |
} |
| 9168 |
} |
| 9169 |
|
| 9170 |
SyncNotedAppOp syncOp = mService.startProxyOperation(clientId, op, |
| 9171 |
attributionSource, false, collectionMode == COLLECT_ASYNC, message, |
| 9172 |
shouldCollectMessage, skipProxyOperation, proxyAttributionFlags, |
| 9173 |
proxiedAttributionFlags, attributionChainId); |
| 9174 |
|
| 9175 |
if (syncOp.getOpMode() == MODE_ALLOWED) { |
| 9176 |
if (collectionMode == COLLECT_SELF) { |
| 9177 |
collectNotedOpForSelf(syncOp); |
| 9178 |
} else if (collectionMode == COLLECT_SYNC |
| 9179 |
|
| 9180 |
&& (mContext.checkPermission(Manifest.permission.UPDATE_APP_OPS_STATS, -1, |
| 9181 |
Process.myUid()) == PackageManager.PERMISSION_GRANTED |
| 9182 |
|| Binder.getCallingUid() == attributionSource.getNextUid())) { |
| 9183 |
collectNotedOpSync(syncOp); |
| 9184 |
} |
| 9185 |
} |
| 9186 |
|
| 9187 |
return syncOp.getOpMode(); |
| 9188 |
} catch (RemoteException e) { |
| 9189 |
throw e.rethrowFromSystemServer(); |
| 9190 |
} |
| 9191 |
} |
| 9192 |
|
| 9193 |
|
| 9194 |
|
| 9195 |
|
| 9196 |
|
| 9197 |
|
| 9198 |
@Deprecated |
| 9199 |
public void finishOp(int op) { |
| 9200 |
finishOp(op, Process.myUid(), mContext.getOpPackageName(), null); |
| 9201 |
} |
| 9202 |
|
| 9203 |
|
| 9204 |
|
| 9205 |
|
| 9206 |
public void finishOp(@NonNull String op, int uid, @NonNull String packageName) { |
| 9207 |
finishOp(strOpToOp(op), uid, packageName, null); |
| 9208 |
} |
| 9209 |
|
| 9210 |
|
| 9211 |
|
| 9212 |
|
| 9213 |
|
| 9214 |
|
| 9215 |
|
| 9216 |
public void finishOp(@NonNull String op, int uid, @NonNull String packageName, |
| 9217 |
@Nullable String attributionTag) { |
| 9218 |
finishOp(strOpToOp(op), uid, packageName, attributionTag); |
| 9219 |
} |
| 9220 |
|
| 9221 |
|
| 9222 |
|
| 9223 |
|
| 9224 |
|
| 9225 |
|
| 9226 |
public void finishOp(int op, int uid, @NonNull String packageName) { |
| 9227 |
finishOp(op, uid, packageName, null); |
| 9228 |
} |
| 9229 |
|
| 9230 |
|
| 9231 |
|
| 9232 |
|
| 9233 |
|
| 9234 |
|
| 9235 |
public void finishOp(int op, int uid, @NonNull String packageName, |
| 9236 |
@Nullable String attributionTag) { |
| 9237 |
finishOp(mContext.getAttributionSource().getToken(), op, uid, packageName, attributionTag); |
| 9238 |
} |
| 9239 |
|
| 9240 |
|
| 9241 |
|
| 9242 |
|
| 9243 |
|
| 9244 |
|
| 9245 |
public void finishOp(IBinder token, int op, int uid, @NonNull String packageName, |
| 9246 |
@Nullable String attributionTag) { |
| 9247 |
try { |
| 9248 |
mService.finishOperation(token, op, uid, packageName, attributionTag); |
| 9249 |
} catch (RemoteException e) { |
| 9250 |
throw e.rethrowFromSystemServer(); |
| 9251 |
} |
| 9252 |
} |
| 9253 |
|
| 9254 |
|
| 9255 |
|
| 9256 |
|
| 9257 |
|
| 9258 |
|
| 9259 |
|
| 9260 |
|
| 9261 |
|
| 9262 |
|
| 9263 |
|
| 9264 |
|
| 9265 |
|
| 9266 |
public void finishProxyOp(@NonNull String op, int proxiedUid, |
| 9267 |
@NonNull String proxiedPackageName, @Nullable String proxiedAttributionTag) { |
| 9268 |
IBinder token = mContext.getAttributionSource().getToken(); |
| 9269 |
finishProxyOp(token, op, new AttributionSource(mContext.getAttributionSource(), |
| 9270 |
new AttributionSource(proxiedUid, proxiedPackageName, proxiedAttributionTag, |
| 9271 |
token)), false); |
| 9272 |
} |
| 9273 |
|
| 9274 |
|
| 9275 |
|
| 9276 |
|
| 9277 |
|
| 9278 |
|
| 9279 |
|
| 9280 |
|
| 9281 |
|
| 9282 |
|
| 9283 |
|
| 9284 |
|
| 9285 |
|
| 9286 |
public void finishProxyOp(@NonNull IBinder clientId, @NonNull String op, |
| 9287 |
@NonNull AttributionSource attributionSource, boolean skipProxyOperation) { |
| 9288 |
try { |
| 9289 |
mService.finishProxyOperation(clientId, strOpToOp(op), attributionSource, |
| 9290 |
skipProxyOperation); |
| 9291 |
} catch (RemoteException e) { |
| 9292 |
throw e.rethrowFromSystemServer(); |
| 9293 |
} |
| 9294 |
} |
| 9295 |
|
| 9296 |
|
| 9297 |
|
| 9298 |
|
| 9299 |
|
| 9300 |
|
| 9301 |
|
| 9302 |
|
| 9303 |
|
| 9304 |
|
| 9305 |
|
| 9306 |
public boolean isOpActive(@NonNull String op, int uid, @NonNull String packageName) { |
| 9307 |
return isOperationActive(strOpToOp(op), uid, packageName); |
| 9308 |
} |
| 9309 |
|
| 9310 |
|
| 9311 |
|
| 9312 |
|
| 9313 |
|
| 9314 |
|
| 9315 |
|
| 9316 |
|
| 9317 |
|
| 9318 |
|
| 9319 |
|
| 9320 |
|
| 9321 |
|
| 9322 |
public boolean isProxying(int op, @NonNull String proxyAttributionTag, int proxiedUid, |
| 9323 |
@NonNull String proxiedPackageName) { |
| 9324 |
try { |
| 9325 |
return mService.isProxying(op, mContext.getOpPackageName(), |
| 9326 |
mContext.getAttributionTag(), proxiedUid, proxiedPackageName); |
| 9327 |
} catch (RemoteException e) { |
| 9328 |
throw e.rethrowFromSystemServer(); |
| 9329 |
} |
| 9330 |
} |
| 9331 |
|
| 9332 |
|
| 9333 |
|
| 9334 |
|
| 9335 |
|
| 9336 |
|
| 9337 |
|
| 9338 |
|
| 9339 |
|
| 9340 |
@TestApi |
| 9341 |
@RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 9342 |
public void resetPackageOpsNoHistory(@NonNull String packageName) { |
| 9343 |
try { |
| 9344 |
mService.resetPackageOpsNoHistory(packageName); |
| 9345 |
} catch (RemoteException e) { |
| 9346 |
throw e.rethrowFromSystemServer(); |
| 9347 |
} |
| 9348 |
} |
| 9349 |
|
| 9350 |
|
| 9351 |
|
| 9352 |
|
| 9353 |
|
| 9354 |
|
| 9355 |
|
| 9356 |
|
| 9357 |
|
| 9358 |
|
| 9359 |
public static void startNotedAppOpsCollection(int callingUid) { |
| 9360 |
sBinderThreadCallingUid.set(callingUid); |
| 9361 |
} |
| 9362 |
|
| 9363 |
|
| 9364 |
|
| 9365 |
|
| 9366 |
|
| 9367 |
|
| 9368 |
|
| 9369 |
|
| 9370 |
public static class PausedNotedAppOpsCollection { |
| 9371 |
final int mUid; |
| 9372 |
final @Nullable ArrayMap<String, long[]> mCollectedNotedAppOps; |
| 9373 |
|
| 9374 |
PausedNotedAppOpsCollection(int uid, @Nullable ArrayMap<String, |
| 9375 |
long[]> collectedNotedAppOps) { |
| 9376 |
mUid = uid; |
| 9377 |
mCollectedNotedAppOps = collectedNotedAppOps; |
| 9378 |
} |
| 9379 |
} |
| 9380 |
|
| 9381 |
|
| 9382 |
|
| 9383 |
|
| 9384 |
|
| 9385 |
|
| 9386 |
|
| 9387 |
|
| 9388 |
|
| 9389 |
|
| 9390 |
public static @Nullable PausedNotedAppOpsCollection pauseNotedAppOpsCollection() { |
| 9391 |
Integer previousUid = sBinderThreadCallingUid.get(); |
| 9392 |
if (previousUid != null) { |
| 9393 |
ArrayMap<String, long[]> previousCollectedNotedAppOps = |
| 9394 |
sAppOpsNotedInThisBinderTransaction.get(); |
| 9395 |
|
| 9396 |
sBinderThreadCallingUid.remove(); |
| 9397 |
sAppOpsNotedInThisBinderTransaction.remove(); |
| 9398 |
|
| 9399 |
return new PausedNotedAppOpsCollection(previousUid, previousCollectedNotedAppOps); |
| 9400 |
} |
| 9401 |
|
| 9402 |
return null; |
| 9403 |
} |
| 9404 |
|
| 9405 |
|
| 9406 |
|
| 9407 |
|
| 9408 |
|
| 9409 |
|
| 9410 |
|
| 9411 |
|
| 9412 |
public static void resumeNotedAppOpsCollection( |
| 9413 |
@Nullable PausedNotedAppOpsCollection prevCollection) { |
| 9414 |
if (prevCollection != null) { |
| 9415 |
sBinderThreadCallingUid.set(prevCollection.mUid); |
| 9416 |
|
| 9417 |
if (prevCollection.mCollectedNotedAppOps != null) { |
| 9418 |
sAppOpsNotedInThisBinderTransaction.set(prevCollection.mCollectedNotedAppOps); |
| 9419 |
} |
| 9420 |
} |
| 9421 |
} |
| 9422 |
|
| 9423 |
|
| 9424 |
|
| 9425 |
|
| 9426 |
|
| 9427 |
|
| 9428 |
|
| 9429 |
|
| 9430 |
|
| 9431 |
|
| 9432 |
public static void finishNotedAppOpsCollection() { |
| 9433 |
sBinderThreadCallingUid.remove(); |
| 9434 |
sAppOpsNotedInThisBinderTransaction.remove(); |
| 9435 |
} |
| 9436 |
|
| 9437 |
|
| 9438 |
|
| 9439 |
|
| 9440 |
|
| 9441 |
|
| 9442 |
|
| 9443 |
private void collectNotedOpForSelf(SyncNotedAppOp syncOp) { |
| 9444 |
synchronized (sLock) { |
| 9445 |
if (sOnOpNotedCallback != null) { |
| 9446 |
sOnOpNotedCallback.onSelfNoted(syncOp); |
| 9447 |
} |
| 9448 |
} |
| 9449 |
sMessageCollector.onSelfNoted(syncOp); |
| 9450 |
} |
| 9451 |
|
| 9452 |
|
| 9453 |
|
| 9454 |
|
| 9455 |
|
| 9456 |
|
| 9457 |
|
| 9458 |
|
| 9459 |
|
| 9460 |
|
| 9461 |
@TestApi |
| 9462 |
public static void collectNotedOpSync(@NonNull SyncNotedAppOp syncOp) { |
| 9463 |
|
| 9464 |
|
| 9465 |
|
| 9466 |
int op = sOpStrToOp.get(syncOp.getOp()); |
| 9467 |
ArrayMap<String, long[]> appOpsNoted = sAppOpsNotedInThisBinderTransaction.get(); |
| 9468 |
if (appOpsNoted == null) { |
| 9469 |
appOpsNoted = new ArrayMap<>(1); |
| 9470 |
sAppOpsNotedInThisBinderTransaction.set(appOpsNoted); |
| 9471 |
} |
| 9472 |
|
| 9473 |
long[] appOpsNotedForAttribution = appOpsNoted.get(syncOp.getAttributionTag()); |
| 9474 |
if (appOpsNotedForAttribution == null) { |
| 9475 |
appOpsNotedForAttribution = new long[2]; |
| 9476 |
appOpsNoted.put(syncOp.getAttributionTag(), appOpsNotedForAttribution); |
| 9477 |
} |
| 9478 |
|
| 9479 |
if (op < 64) { |
| 9480 |
appOpsNotedForAttribution[0] |= 1L << op; |
| 9481 |
} else { |
| 9482 |
appOpsNotedForAttribution[1] |= 1L << (op - 64); |
| 9483 |
} |
| 9484 |
} |
| 9485 |
|
| 9486 |
|
| 9487 |
@Retention(RetentionPolicy.SOURCE) |
| 9488 |
@IntDef(value = { |
| 9489 |
DONT_COLLECT, |
| 9490 |
COLLECT_SELF, |
| 9491 |
COLLECT_SYNC, |
| 9492 |
COLLECT_ASYNC |
| 9493 |
}) |
| 9494 |
private @interface NotedOpCollectionMode {} |
| 9495 |
private static final int DONT_COLLECT = 0; |
| 9496 |
private static final int COLLECT_SELF = 1; |
| 9497 |
private static final int COLLECT_SYNC = 2; |
| 9498 |
private static final int COLLECT_ASYNC = 3; |
| 9499 |
|
| 9500 |
|
| 9501 |
|
| 9502 |
|
| 9503 |
private @NotedOpCollectionMode int getNotedOpCollectionMode(int uid, |
| 9504 |
@Nullable String packageName, int op) { |
| 9505 |
if (packageName == null) { |
| 9506 |
packageName = "android"; |
| 9507 |
} |
| 9508 |
|
| 9509 |
|
| 9510 |
if (sAppOpsToNote[op] == SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED) { |
| 9511 |
boolean shouldCollectNotes; |
| 9512 |
try { |
| 9513 |
shouldCollectNotes = mService.shouldCollectNotes(op); |
| 9514 |
} catch (RemoteException e) { |
| 9515 |
return DONT_COLLECT; |
| 9516 |
} |
| 9517 |
|
| 9518 |
if (shouldCollectNotes) { |
| 9519 |
sAppOpsToNote[op] = SHOULD_COLLECT_NOTE_OP; |
| 9520 |
} else { |
| 9521 |
sAppOpsToNote[op] = SHOULD_NOT_COLLECT_NOTE_OP; |
| 9522 |
} |
| 9523 |
} |
| 9524 |
|
| 9525 |
if (sAppOpsToNote[op] != SHOULD_COLLECT_NOTE_OP) { |
| 9526 |
return DONT_COLLECT; |
| 9527 |
} |
| 9528 |
|
| 9529 |
synchronized (sLock) { |
| 9530 |
if (uid == Process.myUid() |
| 9531 |
&& packageName.equals(ActivityThread.currentOpPackageName())) { |
| 9532 |
return COLLECT_SELF; |
| 9533 |
} |
| 9534 |
} |
| 9535 |
|
| 9536 |
Integer binderUid = sBinderThreadCallingUid.get(); |
| 9537 |
|
| 9538 |
if (binderUid != null && binderUid == uid) { |
| 9539 |
return COLLECT_SYNC; |
| 9540 |
} else { |
| 9541 |
return COLLECT_ASYNC; |
| 9542 |
} |
| 9543 |
} |
| 9544 |
|
| 9545 |
|
| 9546 |
|
| 9547 |
|
| 9548 |
|
| 9549 |
|
| 9550 |
|
| 9551 |
|
| 9552 |
|
| 9553 |
|
| 9554 |
|
| 9555 |
|
| 9556 |
public static void prefixParcelWithAppOpsIfNeeded(@NonNull Parcel p) { |
| 9557 |
ArrayMap<String, long[]> notedAppOps = sAppOpsNotedInThisBinderTransaction.get(); |
| 9558 |
if (notedAppOps == null) { |
| 9559 |
return; |
| 9560 |
} |
| 9561 |
|
| 9562 |
p.writeInt(Parcel.EX_HAS_NOTED_APPOPS_REPLY_HEADER); |
| 9563 |
|
| 9564 |
int numAttributionWithNotesAppOps = notedAppOps.size(); |
| 9565 |
p.writeInt(numAttributionWithNotesAppOps); |
| 9566 |
|
| 9567 |
for (int i = 0; i < numAttributionWithNotesAppOps; i++) { |
| 9568 |
p.writeString(notedAppOps.keyAt(i)); |
| 9569 |
p.writeLong(notedAppOps.valueAt(i)[0]); |
| 9570 |
p.writeLong(notedAppOps.valueAt(i)[1]); |
| 9571 |
} |
| 9572 |
} |
| 9573 |
|
| 9574 |
|
| 9575 |
|
| 9576 |
|
| 9577 |
|
| 9578 |
|
| 9579 |
|
| 9580 |
|
| 9581 |
|
| 9582 |
|
| 9583 |
|
| 9584 |
public static void readAndLogNotedAppops(@NonNull Parcel p) { |
| 9585 |
int numAttributionsWithNotedAppOps = p.readInt(); |
| 9586 |
|
| 9587 |
for (int i = 0; i < numAttributionsWithNotedAppOps; i++) { |
| 9588 |
String attributionTag = p.readString(); |
| 9589 |
long[] rawNotedAppOps = new long[2]; |
| 9590 |
rawNotedAppOps[0] = p.readLong(); |
| 9591 |
rawNotedAppOps[1] = p.readLong(); |
| 9592 |
|
| 9593 |
if (rawNotedAppOps[0] != 0 || rawNotedAppOps[1] != 0) { |
| 9594 |
BitSet notedAppOps = BitSet.valueOf(rawNotedAppOps); |
| 9595 |
|
| 9596 |
synchronized (sLock) { |
| 9597 |
for (int code = notedAppOps.nextSetBit(0); code != -1; |
| 9598 |
code = notedAppOps.nextSetBit(code + 1)) { |
| 9599 |
if (sOnOpNotedCallback != null) { |
| 9600 |
sOnOpNotedCallback.onNoted(new SyncNotedAppOp(code, attributionTag)); |
| 9601 |
} else { |
| 9602 |
String message = getFormattedStackTrace(); |
| 9603 |
sUnforwardedOps.add( |
| 9604 |
new AsyncNotedAppOp(code, Process.myUid(), attributionTag, |
| 9605 |
message, System.currentTimeMillis())); |
| 9606 |
if (sUnforwardedOps.size() > MAX_UNFORWARDED_OPS) { |
| 9607 |
sUnforwardedOps.remove(0); |
| 9608 |
} |
| 9609 |
} |
| 9610 |
} |
| 9611 |
} |
| 9612 |
for (int code = notedAppOps.nextSetBit(0); code != -1; |
| 9613 |
code = notedAppOps.nextSetBit(code + 1)) { |
| 9614 |
sMessageCollector.onNoted(new SyncNotedAppOp(code, attributionTag)); |
| 9615 |
} |
| 9616 |
} |
| 9617 |
} |
| 9618 |
} |
| 9619 |
|
| 9620 |
|
| 9621 |
|
| 9622 |
|
| 9623 |
|
| 9624 |
|
| 9625 |
|
| 9626 |
|
| 9627 |
|
| 9628 |
|
| 9629 |
|
| 9630 |
|
| 9631 |
|
| 9632 |
public void setOnOpNotedCallback(@Nullable @CallbackExecutor Executor asyncExecutor, |
| 9633 |
@Nullable OnOpNotedCallback callback) { |
| 9634 |
Preconditions.checkState((callback == null) == (asyncExecutor == null)); |
| 9635 |
|
| 9636 |
synchronized (sLock) { |
| 9637 |
if (callback == null) { |
| 9638 |
Preconditions.checkState(sOnOpNotedCallback != null, |
| 9639 |
"No callback is currently registered"); |
| 9640 |
|
| 9641 |
try { |
| 9642 |
mService.stopWatchingAsyncNoted(mContext.getPackageName(), |
| 9643 |
sOnOpNotedCallback.mAsyncCb); |
| 9644 |
} catch (RemoteException e) { |
| 9645 |
e.rethrowFromSystemServer(); |
| 9646 |
} |
| 9647 |
|
| 9648 |
sOnOpNotedCallback = null; |
| 9649 |
} else { |
| 9650 |
Preconditions.checkState(sOnOpNotedCallback == null, |
| 9651 |
"Another callback is already registered"); |
| 9652 |
|
| 9653 |
callback.mAsyncExecutor = asyncExecutor; |
| 9654 |
sOnOpNotedCallback = callback; |
| 9655 |
|
| 9656 |
List<AsyncNotedAppOp> missedAsyncOps = null; |
| 9657 |
try { |
| 9658 |
mService.startWatchingAsyncNoted(mContext.getPackageName(), |
| 9659 |
sOnOpNotedCallback.mAsyncCb); |
| 9660 |
missedAsyncOps = mService.extractAsyncOps(mContext.getPackageName()); |
| 9661 |
} catch (RemoteException e) { |
| 9662 |
e.rethrowFromSystemServer(); |
| 9663 |
} |
| 9664 |
|
| 9665 |
|
| 9666 |
OnOpNotedCallback onOpNotedCallback = sOnOpNotedCallback; |
| 9667 |
if (onOpNotedCallback != null && missedAsyncOps != null) { |
| 9668 |
int numMissedAsyncOps = missedAsyncOps.size(); |
| 9669 |
for (int i = 0; i < numMissedAsyncOps; i++) { |
| 9670 |
final AsyncNotedAppOp asyncNotedAppOp = missedAsyncOps.get(i); |
| 9671 |
onOpNotedCallback.getAsyncNotedExecutor().execute( |
| 9672 |
() -> onOpNotedCallback.onAsyncNoted(asyncNotedAppOp)); |
| 9673 |
} |
| 9674 |
} |
| 9675 |
synchronized (this) { |
| 9676 |
int numMissedSyncOps = sUnforwardedOps.size(); |
| 9677 |
if (onOpNotedCallback != null) { |
| 9678 |
for (int i = 0; i < numMissedSyncOps; i++) { |
| 9679 |
final AsyncNotedAppOp syncNotedAppOp = sUnforwardedOps.get(i); |
| 9680 |
onOpNotedCallback.getAsyncNotedExecutor().execute( |
| 9681 |
() -> onOpNotedCallback.onAsyncNoted(syncNotedAppOp)); |
| 9682 |
} |
| 9683 |
} |
| 9684 |
sUnforwardedOps.clear(); |
| 9685 |
} |
| 9686 |
} |
| 9687 |
} |
| 9688 |
} |
| 9689 |
|
| 9690 |
|
| 9691 |
|
| 9692 |
|
| 9693 |
|
| 9694 |
|
| 9695 |
|
| 9696 |
|
| 9697 |
|
| 9698 |
@SystemApi |
| 9699 |
@Deprecated |
| 9700 |
public void setNotedAppOpsCollector(@Nullable AppOpsCollector collector) { |
| 9701 |
synchronized (sLock) { |
| 9702 |
if (collector != null) { |
| 9703 |
if (isListeningForOpNoted()) { |
| 9704 |
setOnOpNotedCallback(null, null); |
| 9705 |
} |
| 9706 |
setOnOpNotedCallback(new HandlerExecutor(Handler.getMain()), collector); |
| 9707 |
} else if (sOnOpNotedCallback != null) { |
| 9708 |
setOnOpNotedCallback(null, null); |
| 9709 |
} |
| 9710 |
} |
| 9711 |
} |
| 9712 |
|
| 9713 |
|
| 9714 |
|
| 9715 |
|
| 9716 |
|
| 9717 |
|
| 9718 |
|
| 9719 |
|
| 9720 |
public static boolean isListeningForOpNoted() { |
| 9721 |
return sOnOpNotedCallback != null || isCollectingStackTraces(); |
| 9722 |
} |
| 9723 |
|
| 9724 |
|
| 9725 |
|
| 9726 |
|
| 9727 |
|
| 9728 |
|
| 9729 |
|
| 9730 |
|
| 9731 |
private static boolean isCollectingStackTraces() { |
| 9732 |
if (sConfig.getSampledOpCode() == OP_NONE && sConfig.getAcceptableLeftDistance() == 0 && |
| 9733 |
sConfig.getExpirationTimeSinceBootMillis() >= SystemClock.elapsedRealtime()) { |
| 9734 |
return false; |
| 9735 |
} |
| 9736 |
return true; |
| 9737 |
} |
| 9738 |
|
| 9739 |
|
| 9740 |
|
| 9741 |
|
| 9742 |
|
| 9743 |
|
| 9744 |
|
| 9745 |
|
| 9746 |
|
| 9747 |
|
| 9748 |
|
| 9749 |
|
| 9750 |
|
| 9751 |
|
| 9752 |
|
| 9753 |
|
| 9754 |
|
| 9755 |
|
| 9756 |
|
| 9757 |
|
| 9758 |
|
| 9759 |
|
| 9760 |
|
| 9761 |
|
| 9762 |
|
| 9763 |
|
| 9764 |
|
| 9765 |
|
| 9766 |
|
| 9767 |
|
| 9768 |
|
| 9769 |
|
| 9770 |
|
| 9771 |
|
| 9772 |
|
| 9773 |
|
| 9774 |
|
| 9775 |
public abstract static class OnOpNotedCallback { |
| 9776 |
private @NonNull Executor mAsyncExecutor; |
| 9777 |
|
| 9778 |
|
| 9779 |
private final IAppOpsAsyncNotedCallback mAsyncCb = new IAppOpsAsyncNotedCallback.Stub() { |
| 9780 |
@Override |
| 9781 |
public void opNoted(AsyncNotedAppOp op) { |
| 9782 |
Objects.requireNonNull(op); |
| 9783 |
|
| 9784 |
final long token = Binder.clearCallingIdentity(); |
| 9785 |
try { |
| 9786 |
getAsyncNotedExecutor().execute(() -> onAsyncNoted(op)); |
| 9787 |
} finally { |
| 9788 |
Binder.restoreCallingIdentity(token); |
| 9789 |
} |
| 9790 |
} |
| 9791 |
}; |
| 9792 |
|
| 9793 |
|
| 9794 |
|
| 9795 |
|
| 9796 |
|
| 9797 |
|
| 9798 |
|
| 9799 |
|
| 9800 |
|
| 9801 |
protected @NonNull Executor getAsyncNotedExecutor() { |
| 9802 |
return mAsyncExecutor; |
| 9803 |
} |
| 9804 |
|
| 9805 |
|
| 9806 |
|
| 9807 |
|
| 9808 |
|
| 9809 |
|
| 9810 |
|
| 9811 |
|
| 9812 |
|
| 9813 |
|
| 9814 |
public abstract void onNoted(@NonNull SyncNotedAppOp op); |
| 9815 |
|
| 9816 |
|
| 9817 |
|
| 9818 |
|
| 9819 |
|
| 9820 |
|
| 9821 |
|
| 9822 |
|
| 9823 |
|
| 9824 |
public abstract void onSelfNoted(@NonNull SyncNotedAppOp op); |
| 9825 |
|
| 9826 |
|
| 9827 |
|
| 9828 |
|
| 9829 |
|
| 9830 |
|
| 9831 |
|
| 9832 |
|
| 9833 |
|
| 9834 |
|
| 9835 |
|
| 9836 |
|
| 9837 |
|
| 9838 |
|
| 9839 |
public abstract void onAsyncNoted(@NonNull AsyncNotedAppOp asyncOp); |
| 9840 |
} |
| 9841 |
|
| 9842 |
|
| 9843 |
|
| 9844 |
|
| 9845 |
|
| 9846 |
|
| 9847 |
|
| 9848 |
|
| 9849 |
|
| 9850 |
@SystemApi |
| 9851 |
@Deprecated |
| 9852 |
public abstract static class AppOpsCollector extends OnOpNotedCallback { |
| 9853 |
public @NonNull Executor getAsyncNotedExecutor() { |
| 9854 |
return new HandlerExecutor(Handler.getMain()); |
| 9855 |
} |
| 9856 |
}; |
| 9857 |
|
| 9858 |
|
| 9859 |
|
| 9860 |
|
| 9861 |
|
| 9862 |
|
| 9863 |
|
| 9864 |
private static String getFormattedStackTrace() { |
| 9865 |
StackTraceElement[] trace = new Exception().getStackTrace(); |
| 9866 |
|
| 9867 |
int firstInteresting = 0; |
| 9868 |
for (int i = 0; i < trace.length; i++) { |
| 9869 |
if (trace[i].getClassName().startsWith(AppOpsManager.class.getName()) |
| 9870 |
|| trace[i].getClassName().startsWith(Parcel.class.getName()) |
| 9871 |
|| trace[i].getClassName().contains("$Stub$Proxy") |
| 9872 |
|| trace[i].getClassName().startsWith(DatabaseUtils.class.getName()) |
| 9873 |
|| trace[i].getClassName().startsWith("android.content.ContentProviderProxy") |
| 9874 |
|| trace[i].getClassName().startsWith(ContentResolver.class.getName())) { |
| 9875 |
firstInteresting = i; |
| 9876 |
} else { |
| 9877 |
break; |
| 9878 |
} |
| 9879 |
} |
| 9880 |
|
| 9881 |
int lastInteresting = trace.length - 1; |
| 9882 |
for (int i = trace.length - 1; i >= 0; i--) { |
| 9883 |
if (trace[i].getClassName().startsWith(HandlerThread.class.getName()) |
| 9884 |
|| trace[i].getClassName().startsWith(Handler.class.getName()) |
| 9885 |
|| trace[i].getClassName().startsWith(Looper.class.getName()) |
| 9886 |
|| trace[i].getClassName().startsWith(Binder.class.getName()) |
| 9887 |
|| trace[i].getClassName().startsWith(RuntimeInit.class.getName()) |
| 9888 |
|| trace[i].getClassName().startsWith(ZygoteInit.class.getName()) |
| 9889 |
|| trace[i].getClassName().startsWith(ActivityThread.class.getName()) |
| 9890 |
|| trace[i].getClassName().startsWith(Method.class.getName()) |
| 9891 |
|| trace[i].getClassName().startsWith("com.android.server.SystemServer")) { |
| 9892 |
lastInteresting = i; |
| 9893 |
} else { |
| 9894 |
break; |
| 9895 |
} |
| 9896 |
} |
| 9897 |
|
| 9898 |
StringBuilder sb = new StringBuilder(); |
| 9899 |
for (int i = firstInteresting; i <= lastInteresting; i++) { |
| 9900 |
if (sFullLog == null) { |
| 9901 |
try { |
| 9902 |
sFullLog = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, |
| 9903 |
FULL_LOG, false); |
| 9904 |
} catch (Exception e) { |
| 9905 |
|
| 9906 |
sFullLog = false; |
| 9907 |
} |
| 9908 |
} |
| 9909 |
|
| 9910 |
if (i != firstInteresting) { |
| 9911 |
sb.append('\n'); |
| 9912 |
} |
| 9913 |
if (!sFullLog && sb.length() + trace[i].toString().length() > 600) { |
| 9914 |
break; |
| 9915 |
} |
| 9916 |
sb.append(trace[i]); |
| 9917 |
} |
| 9918 |
|
| 9919 |
return sb.toString(); |
| 9920 |
} |
| 9921 |
|
| 9922 |
|
| 9923 |
|
| 9924 |
|
| 9925 |
|
| 9926 |
|
| 9927 |
|
| 9928 |
|
| 9929 |
|
| 9930 |
|
| 9931 |
|
| 9932 |
|
| 9933 |
|
| 9934 |
@TestApi |
| 9935 |
|
| 9936 |
|
| 9937 |
public boolean isOperationActive(int code, int uid, String packageName) { |
| 9938 |
try { |
| 9939 |
return mService.isOperationActive(code, uid, packageName); |
| 9940 |
} catch (RemoteException e) { |
| 9941 |
throw e.rethrowFromSystemServer(); |
| 9942 |
} |
| 9943 |
} |
| 9944 |
|
| 9945 |
|
| 9946 |
|
| 9947 |
|
| 9948 |
|
| 9949 |
|
| 9950 |
|
| 9951 |
|
| 9952 |
|
| 9953 |
|
| 9954 |
|
| 9955 |
|
| 9956 |
|
| 9957 |
|
| 9958 |
|
| 9959 |
|
| 9960 |
|
| 9961 |
@TestApi |
| 9962 |
@RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 9963 |
public void setHistoryParameters(@HistoricalMode int mode, long baseSnapshotInterval, |
| 9964 |
int compressionStep) { |
| 9965 |
try { |
| 9966 |
mService.setHistoryParameters(mode, baseSnapshotInterval, compressionStep); |
| 9967 |
} catch (RemoteException e) { |
| 9968 |
throw e.rethrowFromSystemServer(); |
| 9969 |
} |
| 9970 |
} |
| 9971 |
|
| 9972 |
|
| 9973 |
|
| 9974 |
|
| 9975 |
|
| 9976 |
|
| 9977 |
|
| 9978 |
|
| 9979 |
@TestApi |
| 9980 |
@RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 9981 |
public void offsetHistory(long offsetMillis) { |
| 9982 |
try { |
| 9983 |
mService.offsetHistory(offsetMillis); |
| 9984 |
} catch (RemoteException e) { |
| 9985 |
throw e.rethrowFromSystemServer(); |
| 9986 |
} |
| 9987 |
} |
| 9988 |
|
| 9989 |
|
| 9990 |
|
| 9991 |
|
| 9992 |
|
| 9993 |
|
| 9994 |
|
| 9995 |
|
| 9996 |
|
| 9997 |
|
| 9998 |
|
| 9999 |
|
| 10000 |
|
| 10001 |
@TestApi |
| 10002 |
@RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 10003 |
public void addHistoricalOps(@NonNull HistoricalOps ops) { |
| 10004 |
try { |
| 10005 |
mService.addHistoricalOps(ops); |
| 10006 |
} catch (RemoteException e) { |
| 10007 |
throw e.rethrowFromSystemServer(); |
| 10008 |
} |
| 10009 |
} |
| 10010 |
|
| 10011 |
|
| 10012 |
|
| 10013 |
|
| 10014 |
|
| 10015 |
|
| 10016 |
|
| 10017 |
|
| 10018 |
@TestApi |
| 10019 |
@RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 10020 |
public void resetHistoryParameters() { |
| 10021 |
try { |
| 10022 |
mService.resetHistoryParameters(); |
| 10023 |
} catch (RemoteException e) { |
| 10024 |
throw e.rethrowFromSystemServer(); |
| 10025 |
} |
| 10026 |
} |
| 10027 |
|
| 10028 |
|
| 10029 |
|
| 10030 |
|
| 10031 |
|
| 10032 |
|
| 10033 |
@TestApi |
| 10034 |
@RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 10035 |
public void clearHistory() { |
| 10036 |
try { |
| 10037 |
mService.clearHistory(); |
| 10038 |
} catch (RemoteException e) { |
| 10039 |
throw e.rethrowFromSystemServer(); |
| 10040 |
} |
| 10041 |
} |
| 10042 |
|
| 10043 |
|
| 10044 |
|
| 10045 |
|
| 10046 |
|
| 10047 |
|
| 10048 |
|
| 10049 |
|
| 10050 |
|
| 10051 |
|
| 10052 |
@TestApi |
| 10053 |
@RequiresPermission(Manifest.permission.MANAGE_APPOPS) |
| 10054 |
public void rebootHistory(long offlineDurationMillis) { |
| 10055 |
try { |
| 10056 |
mService.rebootHistory(offlineDurationMillis); |
| 10057 |
} catch (RemoteException e) { |
| 10058 |
throw e.rethrowFromSystemServer(); |
| 10059 |
} |
| 10060 |
} |
| 10061 |
|
| 10062 |
|
| 10063 |
|
| 10064 |
|
| 10065 |
|
| 10066 |
|
| 10067 |
|
| 10068 |
|
| 10069 |
@SystemApi |
| 10070 |
@RequiresPermission(Manifest.permission.GET_APP_OPS_STATS) |
| 10071 |
public @Nullable RuntimeAppOpAccessMessage collectRuntimeAppOpAccessMessage() { |
| 10072 |
try { |
| 10073 |
return mService.collectRuntimeAppOpAccessMessage(); |
| 10074 |
} catch (RemoteException e) { |
| 10075 |
throw e.rethrowFromSystemServer(); |
| 10076 |
} |
| 10077 |
} |
| 10078 |
|
| 10079 |
|
| 10080 |
|
| 10081 |
|
| 10082 |
|
| 10083 |
@SystemApi |
| 10084 |
public static String[] getOpStrs() { |
| 10085 |
return Arrays.copyOf(sOpToString, sOpToString.length); |
| 10086 |
} |
| 10087 |
|
| 10088 |
|
| 10089 |
|
| 10090 |
|
| 10091 |
|
| 10092 |
|
| 10093 |
@TestApi |
| 10094 |
public static int getNumOps() { |
| 10095 |
return _NUM_OP; |
| 10096 |
} |
| 10097 |
|
| 10098 |
|
| 10099 |
|
| 10100 |
|
| 10101 |
|
| 10102 |
|
| 10103 |
|
| 10104 |
|
| 10105 |
|
| 10106 |
|
| 10107 |
|
| 10108 |
private static @Nullable NoteOpEvent getLastEvent( |
| 10109 |
@Nullable LongSparseArray<NoteOpEvent> events, @UidState int beginUidState, |
| 10110 |
@UidState int endUidState, @OpFlags int flags) { |
| 10111 |
if (events == null) { |
| 10112 |
return null; |
| 10113 |
} |
| 10114 |
|
| 10115 |
NoteOpEvent lastEvent = null; |
| 10116 |
while (flags != 0) { |
| 10117 |
final int flag = 1 << Integer.numberOfTrailingZeros(flags); |
| 10118 |
flags &= ~flag; |
| 10119 |
for (int uidState : UID_STATES) { |
| 10120 |
if (uidState < beginUidState || uidState > endUidState) { |
| 10121 |
continue; |
| 10122 |
} |
| 10123 |
final long key = makeKey(uidState, flag); |
| 10124 |
|
| 10125 |
NoteOpEvent event = events.get(key); |
| 10126 |
if (lastEvent == null |
| 10127 |
|| event != null && event.getNoteTime() > lastEvent.getNoteTime()) { |
| 10128 |
lastEvent = event; |
| 10129 |
} |
| 10130 |
} |
| 10131 |
} |
| 10132 |
|
| 10133 |
return lastEvent; |
| 10134 |
} |
| 10135 |
|
| 10136 |
private static boolean equalsLongSparseLongArray(@Nullable LongSparseLongArray a, |
| 10137 |
@Nullable LongSparseLongArray b) { |
| 10138 |
if (a == b) { |
| 10139 |
return true; |
| 10140 |
} |
| 10141 |
|
| 10142 |
if (a == null || b == null) { |
| 10143 |
return false; |
| 10144 |
} |
| 10145 |
|
| 10146 |
if (a.size() != b.size()) { |
| 10147 |
return false; |
| 10148 |
} |
| 10149 |
|
| 10150 |
int numEntries = a.size(); |
| 10151 |
for (int i = 0; i < numEntries; i++) { |
| 10152 |
if (a.keyAt(i) != b.keyAt(i) || a.valueAt(i) != b.valueAt(i)) { |
| 10153 |
return false; |
| 10154 |
} |
| 10155 |
} |
| 10156 |
|
| 10157 |
return true; |
| 10158 |
} |
| 10159 |
|
| 10160 |
private static void writeLongSparseLongArrayToParcel( |
| 10161 |
@Nullable LongSparseLongArray array, @NonNull Parcel parcel) { |
| 10162 |
if (array != null) { |
| 10163 |
final int size = array.size(); |
| 10164 |
parcel.writeInt(size); |
| 10165 |
for (int i = 0; i < size; i++) { |
| 10166 |
parcel.writeLong(array.keyAt(i)); |
| 10167 |
parcel.writeLong(array.valueAt(i)); |
| 10168 |
} |
| 10169 |
} else { |
| 10170 |
parcel.writeInt(-1); |
| 10171 |
} |
| 10172 |
} |
| 10173 |
|
| 10174 |
private static @Nullable LongSparseLongArray readLongSparseLongArrayFromParcel( |
| 10175 |
@NonNull Parcel parcel) { |
| 10176 |
final int size = parcel.readInt(); |
| 10177 |
if (size < 0) { |
| 10178 |
return null; |
| 10179 |
} |
| 10180 |
final LongSparseLongArray array = new LongSparseLongArray(size); |
| 10181 |
for (int i = 0; i < size; i++) { |
| 10182 |
array.append(parcel.readLong(), parcel.readLong()); |
| 10183 |
} |
| 10184 |
return array; |
| 10185 |
} |
| 10186 |
|
| 10187 |
private static void writeDiscreteAccessArrayToParcel( |
| 10188 |
@Nullable List<AttributedOpEntry> array, @NonNull Parcel parcel, int flags) { |
| 10189 |
ParceledListSlice<AttributedOpEntry> listSlice = |
| 10190 |
array == null ? null : new ParceledListSlice<>(array); |
| 10191 |
parcel.writeParcelable(listSlice, flags); |
| 10192 |
} |
| 10193 |
|
| 10194 |
private static @Nullable List<AttributedOpEntry> readDiscreteAccessArrayFromParcel( |
| 10195 |
@NonNull Parcel parcel) { |
| 10196 |
final ParceledListSlice<AttributedOpEntry> listSlice = parcel.readParcelable(null, android.content.pm.ParceledListSlice.class); |
| 10197 |
return listSlice == null ? null : listSlice.getList(); |
| 10198 |
} |
| 10199 |
|
| 10200 |
|
| 10201 |
|
| 10202 |
|
| 10203 |
|
| 10204 |
|
| 10205 |
|
| 10206 |
|
| 10207 |
private static LongSparseArray<Object> collectKeys(@Nullable LongSparseLongArray array, |
| 10208 |
@Nullable LongSparseArray<Object> result) { |
| 10209 |
if (array != null) { |
| 10210 |
if (result == null) { |
| 10211 |
result = new LongSparseArray<>(); |
| 10212 |
} |
| 10213 |
final int accessSize = array.size(); |
| 10214 |
for (int i = 0; i < accessSize; i++) { |
| 10215 |
result.put(array.keyAt(i), null); |
| 10216 |
} |
| 10217 |
} |
| 10218 |
return result; |
| 10219 |
} |
| 10220 |
|
| 10221 |
|
| 10222 |
public static String uidStateToString(@UidState int uidState) { |
| 10223 |
switch (uidState) { |
| 10224 |
case UID_STATE_PERSISTENT: { |
| 10225 |
return "UID_STATE_PERSISTENT"; |
| 10226 |
} |
| 10227 |
case UID_STATE_TOP: { |
| 10228 |
return "UID_STATE_TOP"; |
| 10229 |
} |
| 10230 |
case UID_STATE_FOREGROUND_SERVICE_LOCATION: { |
| 10231 |
return "UID_STATE_FOREGROUND_SERVICE_LOCATION"; |
| 10232 |
} |
| 10233 |
case UID_STATE_FOREGROUND_SERVICE: { |
| 10234 |
return "UID_STATE_FOREGROUND_SERVICE"; |
| 10235 |
} |
| 10236 |
case UID_STATE_FOREGROUND: { |
| 10237 |
return "UID_STATE_FOREGROUND"; |
| 10238 |
} |
| 10239 |
case UID_STATE_BACKGROUND: { |
| 10240 |
return "UID_STATE_BACKGROUND"; |
| 10241 |
} |
| 10242 |
case UID_STATE_CACHED: { |
| 10243 |
return "UID_STATE_CACHED"; |
| 10244 |
} |
| 10245 |
default: { |
| 10246 |
return "UNKNOWN"; |
| 10247 |
} |
| 10248 |
} |
| 10249 |
} |
| 10250 |
|
| 10251 |
|
| 10252 |
public static int parseHistoricalMode(@NonNull String mode) { |
| 10253 |
switch (mode) { |
| 10254 |
case "HISTORICAL_MODE_ENABLED_ACTIVE": { |
| 10255 |
return HISTORICAL_MODE_ENABLED_ACTIVE; |
| 10256 |
} |
| 10257 |
case "HISTORICAL_MODE_ENABLED_PASSIVE": { |
| 10258 |
return HISTORICAL_MODE_ENABLED_PASSIVE; |
| 10259 |
} |
| 10260 |
default: { |
| 10261 |
return HISTORICAL_MODE_DISABLED; |
| 10262 |
} |
| 10263 |
} |
| 10264 |
} |
| 10265 |
|
| 10266 |
|
| 10267 |
public static String historicalModeToString(@HistoricalMode int mode) { |
| 10268 |
switch (mode) { |
| 10269 |
case HISTORICAL_MODE_DISABLED: { |
| 10270 |
return "HISTORICAL_MODE_DISABLED"; |
| 10271 |
} |
| 10272 |
case HISTORICAL_MODE_ENABLED_ACTIVE: { |
| 10273 |
return "HISTORICAL_MODE_ENABLED_ACTIVE"; |
| 10274 |
} |
| 10275 |
case HISTORICAL_MODE_ENABLED_PASSIVE: { |
| 10276 |
return "HISTORICAL_MODE_ENABLED_PASSIVE"; |
| 10277 |
} |
| 10278 |
default: { |
| 10279 |
return "UNKNOWN"; |
| 10280 |
} |
| 10281 |
} |
| 10282 |
} |
| 10283 |
|
| 10284 |
private static int getSystemAlertWindowDefault() { |
| 10285 |
final Context context = ActivityThread.currentApplication(); |
| 10286 |
if (context == null) { |
| 10287 |
return AppOpsManager.MODE_DEFAULT; |
| 10288 |
} |
| 10289 |
|
| 10290 |
|
| 10291 |
final PackageManager pm = context.getPackageManager(); |
| 10292 |
|
| 10293 |
if (ActivityManager.isLowRamDeviceStatic() |
| 10294 |
&& !pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK, 0)) { |
| 10295 |
return AppOpsManager.MODE_IGNORED; |
| 10296 |
} |
| 10297 |
|
| 10298 |
return AppOpsManager.MODE_DEFAULT; |
| 10299 |
} |
| 10300 |
|
| 10301 |
|
| 10302 |
|
| 10303 |
|
| 10304 |
|
| 10305 |
public static int leftCircularDistance(int from, int to, int size) { |
| 10306 |
return (to + size - from) % size; |
| 10307 |
} |
| 10308 |
|
| 10309 |
|
| 10310 |
|
| 10311 |
|
| 10312 |
|
| 10313 |
|
| 10314 |
|
| 10315 |
|
| 10316 |
|
| 10317 |
|
| 10318 |
private void collectNoteOpCallsForValidation(int op) { |
| 10319 |
if (NOTE_OP_COLLECTION_ENABLED) { |
| 10320 |
try { |
| 10321 |
mService.collectNoteOpCallsForValidation(getFormattedStackTrace(), |
| 10322 |
op, mContext.getOpPackageName(), mContext.getApplicationInfo().longVersionCode); |
| 10323 |
} catch (RemoteException e) { |
| 10324 |
|
| 10325 |
} |
| 10326 |
} |
| 10327 |
} |
| 10328 |
|
| 10329 |
private static List<AttributedOpEntry> deduplicateDiscreteEvents(List<AttributedOpEntry> list) { |
| 10330 |
int n = list.size(); |
| 10331 |
int i = 0; |
| 10332 |
for (int j = 0, k = 0; j < n; i++, j = k) { |
| 10333 |
long currentAccessTime = list.get(j).getLastAccessTime(OP_FLAGS_ALL); |
| 10334 |
k = j + 1; |
| 10335 |
while(k < n && list.get(k).getLastAccessTime(OP_FLAGS_ALL) == currentAccessTime) { |
| 10336 |
k++; |
| 10337 |
} |
| 10338 |
list.set(i, mergeAttributedOpEntries(list.subList(j, k))); |
| 10339 |
} |
| 10340 |
for (; i < n; i++) { |
| 10341 |
list.remove(list.size() - 1); |
| 10342 |
} |
| 10343 |
return list; |
| 10344 |
} |
| 10345 |
|
| 10346 |
private static AttributedOpEntry mergeAttributedOpEntries(List<AttributedOpEntry> opEntries) { |
| 10347 |
if (opEntries.size() == 1) { |
| 10348 |
return opEntries.get(0); |
| 10349 |
} |
| 10350 |
LongSparseArray<AppOpsManager.NoteOpEvent> accessEvents = new LongSparseArray<>(); |
| 10351 |
LongSparseArray<AppOpsManager.NoteOpEvent> rejectEvents = new LongSparseArray<>(); |
| 10352 |
int opCount = opEntries.size(); |
| 10353 |
for (int i = 0; i < opCount; i++) { |
| 10354 |
AttributedOpEntry a = opEntries.get(i); |
| 10355 |
ArraySet<Long> keys = a.collectKeys(); |
| 10356 |
final int keyCount = keys.size(); |
| 10357 |
for (int k = 0; k < keyCount; k++) { |
| 10358 |
final long key = keys.valueAt(k); |
| 10359 |
|
| 10360 |
final int uidState = extractUidStateFromKey(key); |
| 10361 |
final int flags = extractFlagsFromKey(key); |
| 10362 |
|
| 10363 |
NoteOpEvent access = a.getLastAccessEvent(uidState, uidState, flags); |
| 10364 |
NoteOpEvent reject = a.getLastRejectEvent(uidState, uidState, flags); |
| 10365 |
|
| 10366 |
if (access != null) { |
| 10367 |
NoteOpEvent existingAccess = accessEvents.get(key); |
| 10368 |
if (existingAccess == null || existingAccess.getDuration() == -1) { |
| 10369 |
accessEvents.append(key, access); |
| 10370 |
} else if (existingAccess.mProxy == null && access.mProxy != null ) { |
| 10371 |
existingAccess.mProxy = access.mProxy; |
| 10372 |
} |
| 10373 |
} |
| 10374 |
if (reject != null) { |
| 10375 |
rejectEvents.append(key, reject); |
| 10376 |
} |
| 10377 |
} |
| 10378 |
} |
| 10379 |
return new AttributedOpEntry(opEntries.get(0).mOp, false, accessEvents, rejectEvents); |
| 10380 |
} |
| 10381 |
} |