Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c7c22d4 authored by Nate Myren's avatar Nate Myren
Browse files

Add null check for intent in AppPermissionPreferenceController

Sometimes, the App Info page can be reached without an intent in tests.
Add a null check to catch this

Bug: 154650244
Test: atest AppPermissionPreferenceControllerTest#handlePreferenceTreeClick_shouldStartManagePermissionsActivity

Change-Id: I514acda6b78d9e76b230aa945067bd7d6d9feff9
parent 394f9257
Loading
Loading
Loading
Loading
+20 −12
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.applications.appinfo;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
@@ -123,21 +124,28 @@ public class AppPermissionPreferenceController extends AppInfoPreferenceControll

    private void startManagePermissionsActivity() {
        // start new activity to manage app permissions
        final Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSIONS);
        intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mParent.getAppEntry().info.packageName);
        intent.putExtra(EXTRA_HIDE_INFO_BUTTON, true);
        String action = mParent.getActivity().getIntent().getAction();
        long sessionId = mParent.getActivity().getIntent().getLongExtra(
        final Intent permIntent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSIONS);
        permIntent.putExtra(Intent.EXTRA_PACKAGE_NAME, mParent.getAppEntry().info.packageName);
        permIntent.putExtra(EXTRA_HIDE_INFO_BUTTON, true);
        Activity activity = mParent.getActivity();
        Intent intent = activity != null ? activity.getIntent() : null;
        if (intent != null) {
            String action = intent.getAction();
            long sessionId = intent.getLongExtra(
                    Intent.ACTION_AUTO_REVOKE_PERMISSIONS, INVALID_SESSION_ID);
            if ((action != null && action.equals(Intent.ACTION_AUTO_REVOKE_PERMISSIONS))
                    || sessionId != INVALID_SESSION_ID) {
                // If intent is Auto revoke, and we don't already have a session ID, make one
                while (sessionId == INVALID_SESSION_ID) {
                    sessionId = new Random().nextLong();
                }
            intent.putExtra(Intent.ACTION_AUTO_REVOKE_PERMISSIONS, sessionId);
                permIntent.putExtra(Intent.ACTION_AUTO_REVOKE_PERMISSIONS, sessionId);
            }
        }
        try {
            mParent.getActivity().startActivityForResult(intent, mParent.SUB_INFO_FRAGMENT);
            if (activity != null) {
                activity.startActivityForResult(permIntent, mParent.SUB_INFO_FRAGMENT);
            }
        } catch (ActivityNotFoundException e) {
            Log.w(TAG, "No app can handle android.intent.action.MANAGE_APP_PERMISSIONS");
        }