MediaProjection服务在SystemServiceRegistry的静态块里面注册的
@frameworks/base/core/java/android/app/SystemServiceRegistry.java
public final class SystemServiceRegistry {
private static final String TAG = "SystemServiceRegistry";
/** @hide */
public static boolean sEnableServiceNotFoundWtf = false;
private static int sServiceCacheSize;
private static volatile boolean sInitializing;
// Not instantiable.
private SystemServiceRegistry() { }
static {
registerService(Context.MEDIA_PROJECTION_SERVICE, MediaProjectionManager.class,
申请屏幕录制权限通过启动com.android.systemui/.media.MediaProjectionPermissionActivity来获取权限
requestScreenRecordPermission
Intent captureIntent = u3dClient.createScreenCaptureIntent();
this.mProjectionManager.createScreenCaptureIntent();
//Intent { cmp=com.android.systemui/.media.MediaProjectionPermissionActivity } packagename=com.android.systemui
startActivityForResult(captureIntent, LOCAL_REQUEST_CODE);
@@frameworks/base/packages/SystemUI/src/com/android/systemui/media/MediaProjectionPermissionActivity.java
/*
* 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 static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.media.projection.IMediaProjection;
import android.media.projection.IMediaProjectionManager;
import android.media.projection.MediaProjectionManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.text.BidiFormatter;
import android.text.Span