Skip to content

Commit

Permalink
v6.12: App installation logging improved. Fixed a crash when the file…
Browse files Browse the repository at this point in the history
… URL doesn't contain scheme and domain. Setting sheets can be opened by a Push message. Intents in the runApp push messages may contain data
  • Loading branch information
vmayorow committed Nov 23, 2024
1 parent 6fbed18 commit c9bbef4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ android {
applicationId "com.hmdm.launcher"
minSdkVersion 16
targetSdkVersion 34
versionCode 15110
versionName "6.11"
versionCode 15120
versionName "6.12"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
dataBinding {
enabled = true
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/com/hmdm/launcher/helper/ConfigUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -1042,9 +1042,9 @@ public void onReceive(Context context, Intent intent) {
}
break;
case PackageInstaller.STATUS_SUCCESS:
RemoteLogger.log(context, Const.LOG_DEBUG, "App installed successfully");
String packageName = intent.getStringExtra(Const.PACKAGE_NAME);
if (packageName != null) {
RemoteLogger.log(context, Const.LOG_DEBUG, "App " + packageName + " installed successfully");
Log.i(Const.LOG_TAG, "Install complete: " + packageName);
File file = pendingInstallations.get(packageName);
if (file != null) {
Expand All @@ -1071,18 +1071,23 @@ public void onReceive(Context context, Intent intent) {
if (uiNotifier != null) {
uiNotifier.onAppInstallComplete(packageName);
}
} else {
RemoteLogger.log(context, Const.LOG_DEBUG, "App installed successfully");
}
break;
default:
// Installation failure
String extraMessage = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE);
String statusMessage = InstallUtils.getPackageInstallerStatusMessage(status);
packageName = intent.getStringExtra(Const.PACKAGE_NAME);
String logRecord = "Install failed: " + statusMessage;
if (packageName != null) {
logRecord = packageName + " " + logRecord;
}
if (extraMessage != null && extraMessage.length() > 0) {
logRecord += ", extra: " + extraMessage;
}
RemoteLogger.log(context, Const.LOG_ERROR, logRecord);
packageName = intent.getStringExtra(Const.PACKAGE_NAME);
if (packageName != null) {
File file = pendingInstallations.get(packageName);
if (file != null) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/hmdm/launcher/json/PushMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class PushMessage {
public static final String TYPE_REBOOT = "reboot";
public static final String TYPE_EXIT_KIOSK = "exitKiosk";
public static final String TYPE_CLEAR_DOWNLOADS = "clearDownloadHistory";
public static final String TYPE_SETTINGS = "settings";

public String getMessageType() {
return messageType;
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/hmdm/launcher/util/InstallUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ public static String getRequestSignature(String strUrl) {
}

private static String getFileName(String strUrl) {
return strUrl.substring(strUrl.lastIndexOf("/"));
int slashIndex = strUrl.lastIndexOf("/");
return slashIndex >= 0 ? strUrl.substring(slashIndex) : strUrl;
}

public interface InstallErrorHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Environment;
import android.util.Log;
Expand Down Expand Up @@ -96,6 +97,10 @@ public static void process(PushMessage message, Context context) {
// Clear download history
AsyncTask.execute(() -> clearDownloads(context));
return;
} else if (message.getMessageType().equals(PushMessage.TYPE_SETTINGS)) {
// Clear download history
AsyncTask.execute(() -> openSettings(context, message.getPayloadJSON()));
return;
}

// Send broadcast to all plugins
Expand All @@ -115,11 +120,19 @@ private static void runApplication(Context context, JSONObject payload) {
String pkg = payload.getString("pkg");
String action = payload.optString("action", null);
JSONObject extras = payload.optJSONObject("extra");
String data = payload.optString("data", null);
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(pkg);
if (launchIntent != null) {
if (action != null) {
launchIntent.setAction(action);
}
if (data != null) {
try {
launchIntent.setData(Uri.parse(data));
} catch (Exception e) {
e.printStackTrace();
}
}
if (extras != null) {
Iterator<String> keys = extras.keys();
String key;
Expand Down Expand Up @@ -296,4 +309,23 @@ private static void clearDownloads(Context context) {
}
DownloadTable.deleteAll(db);
}

private static void openSettings(Context context, JSONObject payload) {
if (payload == null) {
RemoteLogger.log(context, Const.LOG_WARN, "Open settings failed: no action specified");
return;
}

try {
String action = payload.getString("action");
Log.d(Const.LOG_TAG, "Opening settings sheet: " + action);
Intent i = new Intent(action);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
} catch (Exception e) {
RemoteLogger.log(context, Const.LOG_WARN, "Open settings failed: " + e.getMessage());
e.printStackTrace();
}
}
}

0 comments on commit c9bbef4

Please sign in to comment.