Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Package info #174

Draft
wants to merge 46 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
617ad1d
play with package info
todi1856 Sep 19, 2022
61fe741
bump version
todi1856 Sep 20, 2022
bbec71f
WIP
todi1856 Oct 14, 2022
853e780
List package entries
todi1856 Oct 15, 2022
7984648
WIP
todi1856 Oct 15, 2022
34976e0
rename
todi1856 Nov 18, 2022
159f014
update
todi1856 Nov 18, 2022
2201271
Use uitoolkit
todi1856 Feb 10, 2023
83f9bbf
Add filter
todi1856 Feb 11, 2023
b189142
sorting enabled
todi1856 Feb 11, 2023
a6d4c2f
Doing package info
todi1856 Feb 11, 2023
e8c89d2
Working on parser
todi1856 Feb 12, 2023
5077315
Move code to AndroidLogcatPackages
todi1856 Feb 12, 2023
5d852df
doing package properties
todi1856 Feb 12, 2023
077daf4
Display data as single entries
todi1856 Feb 12, 2023
838a5ce
Add margins
todi1856 Feb 12, 2023
c913650
slightly fix tooltip
todi1856 Feb 12, 2023
b92fe7f
Move packages to its own folder
todi1856 Feb 23, 2023
e99f457
context menu for packages
todi1856 Feb 23, 2023
05b30d2
context menu for package properties
todi1856 Feb 23, 2023
9bf7dc3
Utilities
todi1856 Feb 23, 2023
76c5240
Doing tabs
todi1856 Feb 24, 2023
98617cd
Doing tabs
todi1856 Feb 24, 2023
4274212
Doing tabs, put them in a box
todi1856 Feb 24, 2023
fc3d77e
doing buttons
todi1856 Feb 24, 2023
adea3df
Bump package version
todi1856 Jun 15, 2023
556a3b3
Move deveice
todi1856 Jun 15, 2023
c2eb764
Fix filtered entries being empty on beginning
todi1856 Jun 15, 2023
01c6c0a
Fix device selection a bit
todi1856 Jun 15, 2023
2800009
Integrate device selection in packages
todi1856 Jun 15, 2023
b10ea58
Make callback only on new device selection
todi1856 Jun 15, 2023
4a921d8
Merge remote-tracking branch 'origin/master' into package-info
todi1856 Jul 17, 2023
e172759
Launchable activities is now a thing
todi1856 Jul 17, 2023
eb74f34
Add vertical view
todi1856 Jul 20, 2023
df22d04
Doing settings
todi1856 Jul 21, 2023
745a8dc
Merge remote-tracking branch 'origin/master' into package-info
todi1856 Aug 8, 2023
b4958f4
Rename
todi1856 Aug 8, 2023
5b4bf08
Show package info from console window
todi1856 Aug 8, 2023
9789375
Add UninstallPackage
todi1856 Aug 8, 2023
a76bec3
DDoing uninstall
todi1856 Aug 8, 2023
3634017
format
todi1856 Aug 8, 2023
37bfc8c
Disable uninstall for system packages
todi1856 Aug 8, 2023
e1f68f0
implement start and launch
todi1856 Aug 10, 2023
50f04d5
Shuffling code
todi1856 Aug 10, 2023
f35a1ec
Merge remote-tracking branch 'origin/master' into package-info
todi1856 Oct 27, 2023
3040801
WIP selected activity
todi1856 Oct 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ private void MenuToolsSelection(object userData, string[] options, int selected)
case ToolsContextMenu.StacktraceUtility:
AndroidLogcatStacktraceWindow.ShowStacktraceWindow();
break;
case ToolsContextMenu.PackageInformation:
AndroidLogcatPackagesWindow.ShowWindow();
break;
case ToolsContextMenu.WindowMemory:
m_Runtime.UserSettings.ExtraWindowState.Type = ExtraWindow.Memory;
break;
Expand All @@ -363,6 +366,7 @@ private void DoToolsGUI()
contextMenu.Add(ToolsContextMenu.ScreenCapture, "Screen Capture");
contextMenu.Add(ToolsContextMenu.OpenTerminal, "Open Terminal");
contextMenu.Add(ToolsContextMenu.StacktraceUtility, "Stacktrace Utility");
contextMenu.Add(ToolsContextMenu.PackageInformation, "Package Information");
var b = m_Runtime.UserSettings.ExtraWindowState.Type;
contextMenu.Add(ToolsContextMenu.WindowMemory, "Window/Memory", b == ExtraWindow.Memory);
contextMenu.Add(ToolsContextMenu.WindowInputs, "Window/Inputs", b == ExtraWindow.Inputs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal enum ToolsContextMenu
ScreenCapture,
OpenTerminal,
StacktraceUtility,
PackageInformation,
WindowMemory,
WindowInputs,
WindowHidden
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;

namespace Unity.Android.Logcat
{
[Serializable]
internal class PackageEntry
{
public string Name { set; get; }
public string Installer { set; get; }
public string UID { set; get; }

internal int GetId() => GetHashCode();

internal void Launch()
{
var adb = AndroidLogcatManager.instance.Runtime.Tools.ADB;
var device = AndroidLogcatManager.instance.Runtime.DeviceQuery.SelectedDevice;
// Not using 'shell am start' since it requires knowing the activity name
var cmd = $"-s {device.Id} shell monkey -p {Name} -c android.intent.category.LAUNCHER 1";
var output = adb.Run(new[] { cmd }, "Unable to launch package");
UnityEngine.Debug.Log(output);
}
internal void Pause()
{
var adb = AndroidLogcatManager.instance.Runtime.Tools.ADB;
var device = AndroidLogcatManager.instance.Runtime.DeviceQuery.SelectedDevice;
var cmd = $"-s {device.Id} shell input keyevent 3";
var output = adb.Run(new[] { cmd }, "Unable to pause the package");
UnityEngine.Debug.Log(output);
}

internal void Stop()
{
var adb = AndroidLogcatManager.instance.Runtime.Tools.ADB;
var device = AndroidLogcatManager.instance.Runtime.DeviceQuery.SelectedDevice;
var cmd = $"-s {device.Id} shell am force-stop {Name}";
var output = adb.Run(new[] { cmd }, "Unable to stop package");
UnityEngine.Debug.Log(output);
}

internal void Uninstall()
{
var adb = AndroidLogcatManager.instance.Runtime.Tools.ADB;
var device = AndroidLogcatManager.instance.Runtime.DeviceQuery.SelectedDevice;
var cmd = $"-s {device.Id} uninstall {Name}";
var output = adb.Run(new[] { cmd }, "Unable to uninstall the package");
UnityEngine.Debug.Log(output);
}

public override string ToString()
{
return $"{Name} Installer={Installer} UID={UID}";
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

184 changes: 184 additions & 0 deletions com.unity.mobile.android-logcat/Editor/AndroidLogcatPackagesWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace Unity.Android.Logcat
{
// adb shell dumpsys package <package>

// adb shell cmd package list packages
// list packages[-f] [-d]
// [-e]
// [-s]
// [-3]
// [-i]
// [-l]
// [-u]
// [-U]
// [--uid UID]
// [--user USER_ID]
// [FILTER]
// Prints all packages; optionally only those whose name contains the text in FILTER.
// Options:
// -f: see their associated file
// -d: filter to only show disabled packages
// -e: filter to only show enabled packages
// -s: filter to only show system packages
// -3: filter to only show third party packages
// -i: see the installer for the packages
// -l: ignored(used for compatibility with older releases)
// -U: also show the package UID
// -u: also include uninstalled packages
// --uid UID: filter to only show packages with the given UID
// --user USER_ID: only list packages belonging to the given user

// Example., adb shell cmd package list packages -3 -U -i

internal class AndroidLogcatPackagesWindow : EditorWindow
{
private GUIContent kRefresh = new GUIContent(L10n.Tr("Refresh"), L10n.Tr("Refresh package list."));

AndroidLogcatRuntimeBase m_Runtime;
AndroidLogcatPackagesView m_Packages;
AndroidLogcatPackagePropertiesView m_PackageProperties;
AndroidLogcatPackageUtilities m_PackageUtilities;
AndroidLogcatDeviceSelection m_DeviceSelection;
TwoPaneSplitView m_HorizontalSplit;
TwoPaneSplitView m_VerticalSplit;

internal static void ShowWindow()
{
// Get existing open window or if none, make a new one:
AndroidLogcatPackagesWindow window = (AndroidLogcatPackagesWindow)EditorWindow.GetWindow(typeof(AndroidLogcatPackagesWindow));
window.titleContent = new UnityEngine.GUIContent("Package Information");
window.Show();
}

private void OnEnable()
{
if (!AndroidBridge.AndroidExtensionsInstalled)
return;

if (rootVisualElement == null)
throw new NullReferenceException("rooVisualElement is null");
rootVisualElement.Insert(0, new IMGUIContainer(DoDebuggingGUI));
rootVisualElement.Insert(0, new IMGUIContainer(DoToolbarGUI));

m_Runtime = AndroidLogcatManager.instance.Runtime;
m_Runtime.Closing += OnDisable;
m_DeviceSelection = new AndroidLogcatDeviceSelection(m_Runtime, OnDeviceSelected);

// TODO: Add query for uxml + clone
var tree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Packages/com.unity.mobile.android-logcat/Editor/UI/Layouts/AndroidLogcatPackagesLayout.uxml");
tree.CloneTree(rootVisualElement);

m_HorizontalSplit = rootVisualElement.Q<TwoPaneSplitView>("HorizontalSplit");
m_HorizontalSplit.RegisterCallback<GeometryChangedEvent>(InitializeHorizontalLayout);

m_VerticalSplit = rootVisualElement.Q<TwoPaneSplitView>("VerticalSplit");
m_VerticalSplit.RegisterCallback<GeometryChangedEvent>(InitializeVerticalLayout);

m_Packages = new AndroidLogcatPackagesView(m_Runtime, rootVisualElement, GetPackageEntries(m_DeviceSelection.SelectedDevice).ToList());
m_Packages.OnPackageSelected = PackageSelected;
m_Packages.OnPackageUninstalled = PackageUninstalled;
m_PackageProperties = new AndroidLogcatPackagePropertiesView(rootVisualElement);
m_PackageUtilities = new AndroidLogcatPackageUtilities(rootVisualElement);

m_Runtime.DeviceQuery.UpdateConnectedDevicesList(true);
}

private void OnDisable()
{
if (!AndroidBridge.AndroidExtensionsInstalled)
return;

if (m_Runtime == null)
return;
if (m_DeviceSelection != null)
{
m_DeviceSelection.Dispose();
m_DeviceSelection = null;
}
m_Runtime = null;
}

private void OnDeviceSelected(IAndroidLogcatDevice selectedDevice)
{
if (m_Packages == null)
throw new Exception("Package view was not created ?");
m_Packages.RefreshEntries(selectedDevice, GetPackageEntries(selectedDevice).ToList());

PackageSelected(m_Packages.SelectedPackage);
}

private void RefreshPackages()
{
OnDeviceSelected(m_DeviceSelection.SelectedDevice);
}

PackageEntry[] GetPackageEntries(IAndroidLogcatDevice selectedDevice)
{
if (selectedDevice == null)
return Array.Empty<PackageEntry>();

return AndroidLogcatUtilities.RetrievePackages(
m_Runtime.Tools.ADB,
selectedDevice);
}

private void InitializeHorizontalLayout(GeometryChangedEvent e)
{
m_HorizontalSplit.fixedPaneInitialDimension = m_HorizontalSplit.layout.width / 2;
m_HorizontalSplit.UnregisterCallback<GeometryChangedEvent>(InitializeHorizontalLayout);
}

private void InitializeVerticalLayout(GeometryChangedEvent e)
{
m_VerticalSplit.fixedPaneInitialDimension = m_VerticalSplit.layout.height * 0.8f;
m_VerticalSplit.UnregisterCallback<GeometryChangedEvent>(InitializeVerticalLayout);
}

void PackageSelected(PackageEntry entry)
{
var parser = new AndroidLogcatPackageInfoParser(AndroidLogcatUtilities.RetrievePackageProperties(
m_Runtime.Tools.ADB, m_DeviceSelection.SelectedDevice, entry));
var entries = parser.ParsePackageInformationAsSingleEntries(entry.Name);
m_PackageProperties.RefreshProperties(entries);

var activities = parser.ParseLaunchableActivities(entry.Name);
m_PackageUtilities.RefreshActivities(m_DeviceSelection.SelectedDevice, entry, activities);
}

void PackageUninstalled(PackageEntry entry)
{
RefreshPackages();
}

void DoToolbarGUI()
{
EditorGUILayout.BeginHorizontal(AndroidLogcatStyles.toolbar);
EditorGUI.BeginDisabledGroup(true);
GUILayout.Label(GUIContent.none, AndroidLogcatStyles.StatusIcon, GUILayout.Width(30));
EditorGUI.EndDisabledGroup();
m_DeviceSelection.DoGUI();
if (GUILayout.Button(kRefresh, AndroidLogcatStyles.toolbarButton))
RefreshPackages();
EditorGUILayout.EndHorizontal();
}

void DoDebuggingGUI()
{
GUILayout.Label("Developer Mode is on, showing debugging buttons:", EditorStyles.boldLabel);
EditorGUILayout.BeginHorizontal(AndroidLogcatStyles.toolbar);

if (GUILayout.Button("Reload Me", AndroidLogcatStyles.toolbarButton))
{
EditorUtility.RequestScriptReload();
}
EditorGUILayout.EndHorizontal();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ namespace Unity.Android.Logcat
[Serializable]
internal class AndroidLogcatUserSettings
{
[Serializable]
internal class PackagePropertiesSettings
{
[SerializeField]
internal string PacakgeFilter;
[SerializeField]
internal string PropertyFilter;
}

[Serializable]
internal class InputSettings
{
Expand Down Expand Up @@ -69,6 +78,8 @@ internal class VideoSettings
private VideoSettings m_CaptureVideoSettings;
[SerializeField]
private InputSettings m_InputSettings;
[SerializeField]
private PackagePropertiesSettings m_PackagePropertiesSettings;

[SerializeField]
private AutoScroll m_AutoScroll;
Expand Down Expand Up @@ -129,7 +140,7 @@ public Priority SelectedPriority

public VideoSettings CaptureVideoSettings { set => m_CaptureVideoSettings = value; get => m_CaptureVideoSettings; }
public InputSettings DeviceInputSettings { set => m_InputSettings = value; get => m_InputSettings; }

public PackagePropertiesSettings PackageWindowSettings { set => m_PackagePropertiesSettings = value; get => m_PackagePropertiesSettings; }
public AutoScroll AutoScroll { set => m_AutoScroll = value; get => m_AutoScroll; }

private void RefreshProcessesForSerialization()
Expand Down
Loading