public void closeSystemDialogs(String reason) { enforceNotIsolatedCaller("closeSystemDialogs"); final int pid = Binder.getCallingPid(); final int uid = Binder.getCallingUid(); final long origId = Binder.clearCallingIdentity(); try { synchronized (mGlobalLock) { Log.d(TAG, "hyj 6811 activitytaskmanagerservice ") // Only allow this from foreground processes, so that background // applications can't abuse it to prevent system UI from being shown. if (uid >= FIRST_APPLICATION_UID) { final WindowProcessController proc = mProcessMap.getProcess(pid); Log.d(TAG, "hyj 6817 activitytaskmanagerservice ") if (!proc.isPerceptible()) { Log.d(TAG, "hyj 6818 activitytaskmanagerservice ") Slog.w(TAG, "Ignoring closeSystemDialogs " + reason + " from background process " + proc); return; } } mWindowManager.closeSystemDialogs(reason); Log.d(TAG, "hyj 6825 activitytaskmanagerservice ") mRootWindowContainer.closeSystemDialogActivities(reason); } // Call into AM outside the synchronized block. Log.d(TAG, "hyj 6829 activitytaskmanagerservice") mAmInternal.broadcastCloseSystemDialogs(reason); } finally { Binder.restoreCallingIdentity(origId); } } 这段代码是什么作用
时间: 2024-02-10 22:18:14 浏览: 145
这段代码是 Android 系统中 ActivityTaskManagerService 类中的 closeSystemDialogs 方法的实现。它的作用是关闭系统对话框,如对话框、通知等。在执行过程中,它会检查调用者的权限,并且只允许前台进程调用该方法。如果调用者是后台进程,则会记录一条警告,并且不执行关闭操作。最后,它会调用 ActivityManagerService 中的 broadcastCloseSystemDialogs 方法,通知系统关闭对话框。
相关问题
package com.music.zds; import android.app.Service; import android.content.Intent; import android.media.MediaPlayer; import android.os.Binder; import android.os.Bundle; import android.os.IBinder; import android.os.Message; import android.util.Log; import java.util.Timer; import java.util.TimerTask; public class MusicService extends Service { public static final String TAG="MusicService"; public MediaPlayer player; private Timer timer; public MusicService() { Log.d(TAG,"MusicService"); } @Override public void onCreate() { super.onCreate(); player=new MediaPlayer(); } @Override public IBinder onBind(Intent intent) { Log.d(TAG,"MusicService()"); return new MusicControler(); } public void addTimer(){ if(timer ==null){ TimerTask task = new TimerTask() { @Override public void run() { if(player == null) return;; int duration = player.getDuration(); int currentPro = player.getCurrentPosition(); Log.w(TAG,"duration:"+duration+",progress:"+currentPro); Message msg = MainActivity.handler.obtainMessage(); Bundle bundle = new Bundle(); bundle.putInt("duration",duration); bundle.putInt("progress",currentPro); msg.setData(bundle); MainActivity.handler.sendMessage(msg); } }; timer.schedule(task,5,500); } } class MusicControler extends Binder{ public void play(){ Log.d(TAG,"play"); try{ player.reset(); player=MediaPlayer.create(getApplicationContext(),R.raw.nianlun,R.raw.jimoyanhuo); player.start(); addTimer(); } catch (Exception e){ e.printStackTrace(); } } public void pause(){ Log.d(TAG,"pause"); player.pause(); } public void continueplay(){ Log.d(TAG,"continueplay"); player.start(); } public void seekTo(int progress){ Log.d(TAG,"seekTo"+progress); player.seekTo(progress); } } @Override public void onDestroy(){ super.onDestroy(); if (player == null) return;; if(player.isPlaying())player.stop(); player.release(); player=null; } }
这是一个 Android 应用程序中的 Service 类,用于播放音乐。它实现了 MediaPlayer 播放器,并提供了一个 Binder 类 MusicControler,用于控制音乐的播放、暂停、继续播放和进度调整等操作。在 onCreate() 方法中初始化了 MediaPlayer 对象,在 onBind() 方法中返回了 MusicControler 实例。在 addTimer() 方法中设置了定时任务,用于定时获取音乐的播放进度,并将进度信息通过 Message 和 Bundle 发送给 MainActivity。在 MusicControler 中的各个方法中调用了 MediaPlayer 对象的相应方法,用于控制音乐的播放进度。在 onDestroy() 方法中释放了 MediaPlayer 对象的资源。
public void broadcastCloseSystemDialogs(String reason) { synchronized (ActivityManagerService.this) { final Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND); Slog.v(TAG_SERVICE,"hyj 19651 startServiceInPackage:"); if (reason != null) { Slog.v(TAG_SERVICE,"hyj 19653 startServiceInPackage:"); intent.putExtra("reason", reason); } broadcastIntentLocked(null, null, null, intent, null, null, 0, null, null, null, OP_NONE, null, false, false, -1, SYSTEM_UID, Binder.getCallingUid(), Binder.getCallingPid(), UserHandle.USER_ALL); } } 这段代码是做什么用
的?
这段代码是用来发送一个名为"Intent.ACTION_CLOSE_SYSTEM_DIALOGS"的广播,用于关闭系统对话框,例如弹出框、菜单等。其中,如果reason不为空,则会在intent中添加一个名为"reason"的额外数据。这个方法运行在ActivityManagerService的上下文中,并且在同步块中执行。
阅读全文