diff options
author | Michael Wright <michaelwr@google.com> | 2014-07-08 18:07:36 -0700 |
---|---|---|
committer | Michael Wright <michaelwr@google.com> | 2014-07-17 14:30:19 -0700 |
commit | c39d47a8e7c74bd539104b0efab898ef6fc43ddf (patch) | |
tree | 98b0c601c9d3b0249e4bd2324aa66ad138e29ad9 /packages | |
parent | 6ccb5f894e11a0ee59c0632643f265427731536e (diff) | |
download | frameworks_base-c39d47a8e7c74bd539104b0efab898ef6fc43ddf.zip frameworks_base-c39d47a8e7c74bd539104b0efab898ef6fc43ddf.tar.gz frameworks_base-c39d47a8e7c74bd539104b0efab898ef6fc43ddf.tar.bz2 |
Add MediaProjection APIs.
The new MediaProjection infrastructure allows the system to hand out
tokens granting the ability to capture the screen's contents, audio,
etc. at a granular level. It's intended to be used both for screen
casting, via the cast APIs, as well as screen sharing via third party
applications.
The screen sharing case is implemented, but all of audio capturing
is still forthcoming.
Change-Id: I4b24669bed7083e11413c10ed8d6b025f5375316
Diffstat (limited to 'packages')
5 files changed, 195 insertions, 1 deletions
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 5752646..a038899 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -109,6 +109,9 @@ <uses-permission android:name="android.permission.CAMERA" /> + <!-- Screen Capturing --> + <uses-permission android:name="android.permission.CREATE_MEDIA_PROJECTION" /> + <application android:name=".SystemUIApplication" android:persistent="true" @@ -245,6 +248,15 @@ android:taskAffinity="com.android.systemui.net" android:excludeFromRecents="true" /> + <!-- started from MediaProjectionManager --> + <activity + android:name=".media.MediaProjectionPermissionActivity" + android:exported="true" + android:theme="@*android:style/Theme.DeviceDefault.Light.Dialog.Alert" + android:finishOnCloseSystemDialogs="true" + android:launchMode="singleTop" + android:excludeFromRecents="true" /> + <!-- platform logo easter egg activity --> <activity android:name=".DessertCase" diff --git a/packages/SystemUI/proguard.flags b/packages/SystemUI/proguard.flags index 6d101d7..c9e1618 100644 --- a/packages/SystemUI/proguard.flags +++ b/packages/SystemUI/proguard.flags @@ -9,4 +9,4 @@ -keep class com.android.systemui.statusbar.phone.PhoneStatusBar -keep class com.android.systemui.statusbar.tv.TvStatusBar --keep class com.android.systemui.recents.*
\ No newline at end of file +-keep class com.android.systemui.recents.* diff --git a/packages/SystemUI/res/layout/remember_permission_checkbox.xml b/packages/SystemUI/res/layout/remember_permission_checkbox.xml new file mode 100644 index 0000000..a21acb3 --- /dev/null +++ b/packages/SystemUI/res/layout/remember_permission_checkbox.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<!-- Check box that is displayed in the activity resolver UI for the user + to make their selection the preferred activity. --> +<FrameLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingStart="8dp" + android:paddingEnd="8dp" + android:paddingTop="8dp"> + + <CheckBox + android:id="@+id/remember" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:focusable="true" + android:clickable="true" + android:text="@string/media_projection_remember_text" /> +</FrameLayout> diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index f8c9d4c..46057af 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -703,5 +703,15 @@ <!-- Text shown in place of notification contents when the notification is hidden on a secure lockscreen --> <string name="notification_hidden_text">Contents hidden</string> + <string name="guest_exit_guest">Exit guest</string> + + <!-- Media projection permission dialog warning text. [CHAR LIMIT=NONE] --> + <string name="media_projection_dialog_text"><xliff:g id="app_seeking_permission" example="Hangouts">%s</xliff:g> will start capturing everything that\'s displayed on your screen.</string> + + <!-- Media projection permission dialog permanent grant check box. [CHAR LIMIT=NONE] --> + <string name="media_projection_remember_text">Don\'t show again</string> + + <!-- Media projection permission dialog action text. [CHAR LIMIT=60] --> + <string name="media_projection_action_text">Start now</string> </resources> diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java b/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java new file mode 100644 index 0000000..b441eaa --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.media; + +import android.app.AlertDialog; +import android.app.PendingIntent; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.media.projection.MediaProjectionManager; +import android.media.projection.IMediaProjectionManager; +import android.media.projection.IMediaProjection; +import android.os.Bundle; +import android.os.IBinder; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.util.Log; +import android.view.LayoutInflater; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.TextView; + +import com.android.internal.app.AlertActivity; +import com.android.internal.app.AlertController; +import com.android.systemui.R; + +public class MediaProjectionPermissionActivity extends AlertActivity + implements DialogInterface.OnClickListener, CheckBox.OnCheckedChangeListener { + private static final String TAG = "MediaProjectionPermissionActivity"; + + private boolean mPermanentGrant; + private String mPackageName; + private int mUid; + private IMediaProjectionManager mService; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + + Intent intent = getIntent(); + 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(); + + final AlertController.AlertParams ap = mAlertParams; + ap.mIcon = aInfo.loadIcon(packageManager); + ap.mMessage = getString(R.string.media_projection_dialog_text, appName); + ap.mPositiveButtonText = getString(R.string.media_projection_action_text); + ap.mNegativeButtonText = getString(android.R.string.cancel); + ap.mPositiveButtonListener = this; + ap.mNegativeButtonListener = this; + + // add "always use" checkbox + LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); + ap.mView = inflater.inflate(R.layout.remember_permission_checkbox, null); + CheckBox rememberPermissionCheckbox = + (CheckBox)ap.mView.findViewById(R.id.remember); + rememberPermissionCheckbox.setOnCheckedChangeListener(this); + + setupAlert(); + } + + @Override + public void onClick(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 { + finish(); + } + } + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + mPermanentGrant = isChecked; + } + + private Intent getMediaProjectionIntent(int uid, String packageName, boolean permanentGrant) + throws RemoteException { + 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; + } +} |