FileDocCategorySizeDatePackage
MediaProjectionPermissionActivity.javaAPI DocAndroid 5.1 API5330Thu Mar 12 22:22:42 GMT 2015com.android.systemui.media

MediaProjectionPermissionActivity

public class MediaProjectionPermissionActivity extends android.app.Activity implements CheckBox.OnCheckedChangeListener, DialogInterface.OnClickListener, DialogInterface.OnCancelListener

Fields Summary
private static final String
TAG
private boolean
mPermanentGrant
private String
mPackageName
private int
mUid
private android.media.projection.IMediaProjectionManager
mService
private android.app.AlertDialog
mDialog
Constructors Summary
Methods Summary
private android.content.IntentgetMediaProjectionIntent(int uid, java.lang.String packageName, boolean permanentGrant)

        IMediaProjection projection = mService.createProjection(uid, packageName,
                 MediaProjectionManager.TYPE_SCREEN_CAPTURE, permanentGrant);
        Intent intent = new Intent();
        intent.putExtra(MediaProjectionManager.EXTRA_MEDIA_PROJECTION, projection.asBinder());
        return intent;
    
public voidonCancel(android.content.DialogInterface dialog)

        finish();
    
public voidonCheckedChanged(android.widget.CompoundButton buttonView, boolean isChecked)

        mPermanentGrant = isChecked;
    
public voidonClick(android.content.DialogInterface dialog, int which)

        try {
            if (which == AlertDialog.BUTTON_POSITIVE) {
                setResult(RESULT_OK, getMediaProjectionIntent(
                        mUid, mPackageName, mPermanentGrant));
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Error granting projection permission", e);
            setResult(RESULT_CANCELED);
        } finally {
            mDialog.dismiss();
            finish();
        }
    
public voidonCreate(android.os.Bundle icicle)


    
        
        super.onCreate(icicle);

        mPackageName = getCallingPackage();
        IBinder b = ServiceManager.getService(MEDIA_PROJECTION_SERVICE);
        mService = IMediaProjectionManager.Stub.asInterface(b);

        if (mPackageName == null) {
            finish();
            return;
        }

        PackageManager packageManager = getPackageManager();
        ApplicationInfo aInfo;
        try {
            aInfo = packageManager.getApplicationInfo(mPackageName, 0);
            mUid = aInfo.uid;
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, "unable to look up package name", e);
            finish();
            return;
        }

        try {
            if (mService.hasProjectionPermission(mUid, mPackageName)) {
                setResult(RESULT_OK, getMediaProjectionIntent(mUid, mPackageName,
                        false /*permanentGrant*/));
                finish();
                return;
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Error checking projection permissions", e);
            finish();
            return;
        }

        String appName = aInfo.loadLabel(packageManager).toString();

        mDialog = new AlertDialog.Builder(this)
                .setIcon(aInfo.loadIcon(packageManager))
                .setMessage(getString(R.string.media_projection_dialog_text, appName))
                .setPositiveButton(R.string.media_projection_action_text, this)
                .setNegativeButton(android.R.string.cancel, this)
                .setView(R.layout.remember_permission_checkbox)
                .setOnCancelListener(this)
                .create();

        mDialog.create();

        ((CheckBox) mDialog.findViewById(R.id.remember)).setOnCheckedChangeListener(this);
        mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

        mDialog.show();
    
protected voidonDestroy()

        super.onDestroy();
        mDialog.dismiss();