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

Commit 287c6123 authored by Ruben Brunk's avatar Ruben Brunk Committed by android-build-merger
Browse files

Merge "Update dumpsys logging for VrManagerService." into nyc-dev

am: aa262c86

* commit 'aa262c86':
  Update dumpsys logging for VrManagerService.

Change-Id: I4b18c6f23eb065d31cb71003078ef5d0e6cba441
parents 98f91884 aa262c86
Loading
Loading
Loading
Loading
+24 −0
Original line number Original line Diff line number Diff line
@@ -207,6 +207,30 @@ public class EnabledComponentsObserver implements SettingChangeListener {
        }
        }
    }
    }


    /**
     * Return all VrListenerService components installed for this user.
     *
     * @param userId ID of the user to check.
     * @return a set of {@link ComponentName}s.
     */
    public ArraySet<ComponentName> getInstalled(int userId) {
        synchronized (mLock) {
            return mInstalledSet.get(userId);
        }
    }

    /**
     * Return all VrListenerService components enabled for this user.
     *
     * @param userId ID of the user to check.
     * @return a set of {@link ComponentName}s.
     */
    public ArraySet<ComponentName> getEnabled(int userId) {
        synchronized (mLock) {
            return mEnabledSet.get(userId);
        }
    }

    private int[] getCurrentProfileIds() {
    private int[] getCurrentProfileIds() {
        UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        if (userManager == null) {
        if (userManager == null) {
+99 −14
Original line number Original line Diff line number Diff line
@@ -59,12 +59,13 @@ import com.android.server.utils.ManagedApplicationService.BinderChecker;
import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.lang.StringBuilder;
import java.lang.StringBuilder;
import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.List;
import java.util.Objects;
import java.util.Objects;
import java.util.Set;


/**
/**
 * Service tracking whether VR mode is active, and notifying listening services of state changes.
 * Service tracking whether VR mode is active, and notifying listening services of state changes.
@@ -93,6 +94,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC
    public static final String VR_MANAGER_BINDER_SERVICE = "vrmanager";
    public static final String VR_MANAGER_BINDER_SERVICE = "vrmanager";


    private static final int PENDING_STATE_DELAY_MS = 300;
    private static final int PENDING_STATE_DELAY_MS = 300;
    private static final int EVENT_LOG_SIZE = 32;


    private static native void initializeNative();
    private static native void initializeNative();
    private static native void setVrModeNative(boolean enabled);
    private static native void setVrModeNative(boolean enabled);
@@ -117,6 +119,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC
    private String mPreviousCoarseLocationPackage;
    private String mPreviousCoarseLocationPackage;
    private String mPreviousManageOverlayPackage;
    private String mPreviousManageOverlayPackage;
    private VrState mPendingState;
    private VrState mPendingState;
    private final ArrayDeque<VrState> mLoggingDeque = new ArrayDeque<>(EVENT_LOG_SIZE);


    private static final int MSG_VR_STATE_CHANGE = 0;
    private static final int MSG_VR_STATE_CHANGE = 0;
    private static final int MSG_PENDING_VR_STATE_CHANGE = 1;
    private static final int MSG_PENDING_VR_STATE_CHANGE = 1;
@@ -154,6 +157,8 @@ public class VrManagerService extends SystemService implements EnabledComponentC
        final int userId;
        final int userId;
        final ComponentName targetPackageName;
        final ComponentName targetPackageName;
        final ComponentName callingPackage;
        final ComponentName callingPackage;
        final long timestamp;
        final boolean defaultPermissionsGranted;


        VrState(boolean enabled, ComponentName targetPackageName, int userId,
        VrState(boolean enabled, ComponentName targetPackageName, int userId,
                ComponentName callingPackage) {
                ComponentName callingPackage) {
@@ -161,8 +166,20 @@ public class VrManagerService extends SystemService implements EnabledComponentC
            this.userId = userId;
            this.userId = userId;
            this.targetPackageName = targetPackageName;
            this.targetPackageName = targetPackageName;
            this.callingPackage = callingPackage;
            this.callingPackage = callingPackage;
            this.defaultPermissionsGranted = false;
            this.timestamp = System.currentTimeMillis();
        }

        VrState(boolean enabled, ComponentName targetPackageName, int userId,
            ComponentName callingPackage, boolean defaultPermissionsGranted) {
            this.enabled = enabled;
            this.userId = userId;
            this.targetPackageName = targetPackageName;
            this.callingPackage = callingPackage;
            this.defaultPermissionsGranted = defaultPermissionsGranted;
            this.timestamp = System.currentTimeMillis();
        }
    }
    }
    };


    private static final BinderChecker sBinderChecker = new BinderChecker() {
    private static final BinderChecker sBinderChecker = new BinderChecker() {
        @Override
        @Override
@@ -235,22 +252,42 @@ public class VrManagerService extends SystemService implements EnabledComponentC
                        + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
                        + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
                return;
                return;
            }
            }
            pw.print("mVrModeEnabled=");
            pw.println("********* Dump of VrManagerService *********");
            pw.println(mVrModeEnabled);
            pw.println("Previous state transitions:\n");
            pw.print("mCurrentVrModeUser=");
            String tab = "  ";
            pw.println(mCurrentVrModeUser);
            dumpStateTransitions(pw);
            pw.print("mRemoteCallbacks=");
            pw.println("\n\nRemote Callbacks:");
            int i=mRemoteCallbacks.beginBroadcast(); // create the broadcast item array
            int i=mRemoteCallbacks.beginBroadcast(); // create the broadcast item array
            while(i-->0) {
            while(i-->0) {
                pw.print(tab);
                pw.print(mRemoteCallbacks.getBroadcastItem(i));
                pw.print(mRemoteCallbacks.getBroadcastItem(i));
                if (i>0) pw.print(", ");
                if (i>0) pw.println(",");
            }
            }
            mRemoteCallbacks.finishBroadcast();
            mRemoteCallbacks.finishBroadcast();
            pw.println();
            pw.println("\n");
            pw.print("mCurrentVrService=");
            pw.println("Installed VrListenerService components:");
            pw.println(mCurrentVrService != null ? mCurrentVrService.getComponent() : "(none)");
            int userId = mCurrentVrModeUser;
            pw.print("mCurrentVrModeComponent=");
            ArraySet<ComponentName> installed = mComponentObserver.getInstalled(userId);
            pw.println(mCurrentVrModeComponent);
            if (installed == null || installed.size() == 0) {
                pw.println("None");
            } else {
                for (ComponentName n : installed) {
                    pw.print(tab);
                    pw.println(n.flattenToString());
                }
            }
            pw.println("Enabled VrListenerService components:");
            ArraySet<ComponentName> enabled = mComponentObserver.getEnabled(userId);
            if (enabled == null || enabled.size() == 0) {
                pw.println("None");
            } else {
                for (ComponentName n : enabled) {
                    pw.print(tab);
                    pw.println(n.flattenToString());
                }
            }
            pw.println("\n");
            pw.println("********* End of VrManagerService Dump *********");
        }
        }


    };
    };
@@ -486,6 +523,9 @@ public class VrManagerService extends SystemService implements EnabledComponentC


            boolean validUserComponent = (mComponentObserver.isValid(component, userId) ==
            boolean validUserComponent = (mComponentObserver.isValid(component, userId) ==
                    EnabledComponentsObserver.NO_ERROR);
                    EnabledComponentsObserver.NO_ERROR);
            if (!mVrModeEnabled && !enabled) {
                return validUserComponent; // Disabled -> Disabled transition does nothing.
            }


            // Always send mode change events.
            // Always send mode change events.
            changeVrModeLocked(enabled, (enabled && validUserComponent) ? component : null);
            changeVrModeLocked(enabled, (enabled && validUserComponent) ? component : null);
@@ -539,6 +579,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC
                    }
                    }
                });
                });
            }
            }
            logStateLocked();


            return validUserComponent;
            return validUserComponent;
        } finally {
        } finally {
@@ -827,6 +868,50 @@ public class VrManagerService extends SystemService implements EnabledComponentC
        }
        }
    }
    }


    private void logStateLocked() {
        ComponentName currentBoundService = (mCurrentVrService == null) ? null :
            mCurrentVrService.getComponent();
        VrState current = new VrState(mVrModeEnabled, currentBoundService, mCurrentVrModeUser,
            mCurrentVrModeComponent, mWasDefaultGranted);
        if (mLoggingDeque.size() == EVENT_LOG_SIZE) {
            mLoggingDeque.removeFirst();
        }
        mLoggingDeque.add(current);
    }

    private void dumpStateTransitions(PrintWriter pw) {
        SimpleDateFormat d = new SimpleDateFormat("MM-dd HH:mm:ss.SSS");
        String tab = "  ";
        if (mLoggingDeque.size() == 0) {
            pw.print(tab);
            pw.println("None");
        }
        for (VrState state : mLoggingDeque) {
            pw.print(d.format(new Date(state.timestamp)));
            pw.print(tab);
            pw.print("State changed to:");
            pw.print(tab);
            pw.println((state.enabled) ? "ENABLED" : "DISABLED");
            if (state.enabled) {
                pw.print(tab);
                pw.print("User=");
                pw.println(state.userId);
                pw.print(tab);
                pw.print("Current VR Activity=");
                pw.println((state.callingPackage == null) ?
                    "None" : state.callingPackage.flattenToString());
                pw.print(tab);
                pw.print("Bound VrListenerService=");
                pw.println((state.targetPackageName == null) ?
                    "None" : state.targetPackageName.flattenToString());
                if (state.defaultPermissionsGranted) {
                    pw.print(tab);
                    pw.println("Default permissions granted to the bound VrListenerService.");
                }
            }
        }
    }

    /*
    /*
     * Implementation of VrManagerInternal calls.  These are callable from system services.
     * Implementation of VrManagerInternal calls.  These are callable from system services.
     */
     */