PlayerBase: reference to IAppOpsService may be null

The reference to IAppOpsService may be null for a player
  that failed to be initialized correctly, account for this.

Test: see bug
Bug 35415129

Change-Id: I9da40b87736a7890fcb63640eeabd17d0da3d5d3
This commit is contained in:
Jean-Michel Trivi
2017-02-23 10:21:17 -08:00
parent 0f09817859
commit 0fbcb86389

View File

@@ -58,7 +58,7 @@ public abstract class PlayerBase {
protected float mAuxEffectSendLevel = 0.0f;
// for AppOps
private IAppOpsService mAppOps;
private IAppOpsService mAppOps; // may be null
private IAppOpsCallback mAppOpsCallback;
private boolean mHasAppOpsPlayAudio = true; // sync'd on mLock
private final Object mLock = new Object();
@@ -251,7 +251,9 @@ public abstract class PlayerBase {
Log.e(TAG, "Error talking to audio service, the player will still be tracked", e);
}
try {
mAppOps.stopWatchingMode(mAppOpsCallback);
if (mAppOps != null) {
mAppOps.stopWatchingMode(mAppOpsCallback);
}
} catch (RemoteException e) {
// nothing to do here, the object is supposed to be released anyway
}
@@ -264,9 +266,12 @@ public abstract class PlayerBase {
void updateAppOpsPlayAudio_sync() {
boolean oldHasAppOpsPlayAudio = mHasAppOpsPlayAudio;
try {
final int mode = mAppOps.checkAudioOperation(AppOpsManager.OP_PLAY_AUDIO,
int mode = AppOpsManager.MODE_IGNORED;
if (mAppOps != null) {
mode = mAppOps.checkAudioOperation(AppOpsManager.OP_PLAY_AUDIO,
mAttributes.getUsage(),
Process.myUid(), ActivityThread.currentPackageName());
}
mHasAppOpsPlayAudio = (mode == AppOpsManager.MODE_ALLOWED);
} catch (RemoteException e) {
mHasAppOpsPlayAudio = false;