Skip to content

Commit

Permalink
Make A10 work
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshine0523 committed Sep 6, 2023
1 parent f6465e7 commit 101a2b7
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ object MiFreeformServiceManager {
iMiFreeformService?.removeFreeform(freeformId)
}

fun getLog(): String? {
return iMiFreeformService?.log
fun getLog(): String {
return iMiFreeformService?.log ?: "Maybe Mi-Freeform can`t link mi_freeform service. You can get log at /data/system/mi_freeform/log.log"
}

fun clearLog() {
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/com/sunshine/freeform/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ class MainActivity : ComponentActivity() {
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ScaffoldWidget(mainViewModel: MainViewModel, saveLogsLauncher: ActivityResultLauncher<String>) {
val items = mutableListOf("Home")
val items = mutableListOf("Home", "Log")
if (MiFreeformServiceManager.ping()) items.add("Setting")
items.add("Log")

var selectedIndex by remember {
mutableIntStateOf(0)
}
Expand All @@ -107,8 +107,8 @@ fun ScaffoldWidget(mainViewModel: MainViewModel, saveLogsLauncher: ActivityResul
Box(modifier = Modifier.padding(it)) {
when (selectedIndex) {
0 -> HomeWidget()
1 -> SettingWidget(mainViewModel)
2 -> LogWidget(mainViewModel)
1 -> LogWidget(mainViewModel)
2 -> SettingWidget(mainViewModel)
}
}
}
Expand All @@ -126,7 +126,7 @@ fun TopBarWidget(
Text(text = getTitle(index = selectedIndex))
},
actions = {
if (selectedIndex == 2) {
if (selectedIndex == 1) {
IconButton(
onClick = {
viewModel.setLogSoftWrap(viewModel.logSoftWrap.value?.not()?:true)
Expand Down Expand Up @@ -157,8 +157,8 @@ fun TopBarWidget(
private fun getTitle(index: Int): String {
return when (index) {
0 -> stringResource(id = R.string.app_name)
1 -> stringResource(id =R.string.setting)
2 -> stringResource(id = R.string.log)
1 -> stringResource(id = R.string.log)
2 -> stringResource(id =R.string.setting)
else -> stringResource(id = R.string.app_name)
}
}
Expand All @@ -167,8 +167,8 @@ private fun getTitle(index: Int): String {
private fun getNavigationIcon(index: Int): Painter{
return when (index) {
0 -> painterResource(id = R.drawable.ic_home)
1 -> painterResource(id = R.drawable.ic_setting)
2 -> painterResource(id = R.drawable.ic_log)
1 -> painterResource(id = R.drawable.ic_log)
2 -> painterResource(id = R.drawable.ic_setting)
else -> painterResource(id = R.drawable.ic_home)
}
}
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ subprojects {
minSdk = androidMinSdkVersion
if (this is ApplicationDefaultConfig) {
targetSdk = androidTargetSdkVersion
versionCode = 3000
versionName = "3.0.0-Preview"
versionCode = 3001
versionName = "3.0.1-Preview"
}
}

Expand Down
2 changes: 2 additions & 0 deletions freeform-server/src/main/assets/post-fs-data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
magiskpolicy --live "allow untrusted_app default_android_service service_manager find"
magiskpolicy --live "allow system_server default_android_service service_manager add"
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public static void startApp(Context context, AppConfig appConfig, int displayId)
intent.addCategory(Intent.CATEGORY_LAUNCHER);
ActivityOptions activityOptions = ActivityOptions.makeBasic();
activityOptions.setLaunchDisplayId(displayId);
ActivityOptions.class.getMethod("setCallerDisplayId", int.class).invoke(activityOptions, displayId);
Context.class.getMethod("startActivityAsUser", Intent.class, Bundle.class, UserHandleHidden.class)
.invoke(context, intent, activityOptions.toBundle(), new UserHandleHidden(appConfig.getUserId()));
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ public MiFreeformUIService(Context context, MiFreeformDisplayAdapter miFreeformD
this.uiHandler = uiHandler;
this.settings = DataHelper.INSTANCE.getSettings();
SystemServiceHolder.init(() -> {
try {
ServiceManager.addService("mi_freeform", this);
Map<String, IBinder> cache = new ArrayMap<>();
cache.put("mi_freeform", this);
ServiceManager.initServiceCache(cache);
MLog.i(TAG, "add mi_freeform SystemService: " + ServiceManager.getService("mi_freeform"));
} catch (Exception e) {
MLog.e(TAG, "add mi_freeform service failed, " + e);
}
if (ServiceManager.getService("mi_freeform") == null) return;
this.sideBarService = new SideBarService(context, uiHandler, settings);
ServiceManager.addService("mi_freeform", this);
Map<String, IBinder> cache = new ArrayMap<>();
cache.put("mi_freeform", this);
ServiceManager.initServiceCache(cache);
MLog.i(TAG, "add mi_freeform SystemService: " + ServiceManager.getService("mi_freeform"));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class FreeformTaskStackListener(
) : ITaskStackListener.Stub() {

var taskId = -1
//For A10
var stackId = -1

companion object {
private const val TAG = "Mi-Freeform/FreeformTaskStackListener"
Expand Down Expand Up @@ -79,17 +81,29 @@ class FreeformTaskStackListener(

override fun onTaskMovedToFront(taskInfo: ActivityManager.RunningTaskInfo) {
Log.i(TAG, "onTaskMovedToFront $taskInfo")
val displayId = taskInfo::class.java.getField("displayId").get(taskInfo) as Int
if (this.displayId == displayId) taskId = taskInfo.taskId
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val displayId = taskInfo::class.java.getField("displayId").get(taskInfo) as Int
if (this.displayId == displayId) taskId = taskInfo.taskId
}
}

override fun onTaskDescriptionChanged(taskInfo: ActivityManager.RunningTaskInfo?) {
Log.i(TAG, "onTaskDescriptionChanged $taskInfo")
//A10 A11 maybe not called onTaskMovedToFront. So use this func
if (Build.VERSION.SDK_INT in Build.VERSION_CODES.Q .. Build.VERSION_CODES.R) {
if (taskInfo != null) {
val displayId = taskInfo::class.java.getField("displayId").get(taskInfo) as Int
if (this.displayId == displayId) taskId = taskInfo.taskId
when (Build.VERSION.SDK_INT) {
Build.VERSION_CODES.R -> {
if (taskInfo != null) {
val displayId = taskInfo::class.java.getField("displayId").get(taskInfo) as Int
if (this.displayId == displayId) taskId = taskInfo.taskId
}
}
Build.VERSION_CODES.Q -> {
if (taskInfo != null) {
val displayId = taskInfo::class.java.getField("displayId").get(taskInfo) as Int
val stackId = taskInfo::class.java.getField("stackId").get(taskInfo) as Int
this.taskId = taskInfo.taskId
if (this.displayId == displayId) this.stackId = stackId
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.sunshine0523.freeform.ui.freeform

import android.annotation.SuppressLint
import android.os.Build
import android.view.Display
import android.view.GestureDetector.SimpleOnGestureListener
import android.view.MotionEvent
Expand Down Expand Up @@ -50,7 +51,13 @@ class LeftViewClickListener(private val window: FreeformWindow) : View.OnClickLi
*/
class LeftViewLongClickListener(private val window: FreeformWindow): View.OnLongClickListener {
override fun onLongClick(v: View): Boolean {
if (null != window.freeformTaskStackListener) SystemServiceHolder.activityTaskManager.moveRootTaskToDisplay(window.freeformTaskStackListener!!.taskId, Display.DEFAULT_DISPLAY)
if (null != window.freeformTaskStackListener) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
SystemServiceHolder.activityTaskManager.moveRootTaskToDisplay(window.freeformTaskStackListener!!.taskId, Display.DEFAULT_DISPLAY)
} else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.Q) {
SystemServiceHolder.activityTaskManager.moveStackToDisplay(window.freeformTaskStackListener!!.stackId, Display.DEFAULT_DISPLAY)
}
}
window.destroy(false)
// FreeformAnimation.toFullScreen(window, 500, object : AnimatorListener {
// override fun onAnimationEnd(p0: Animator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface IActivityTaskManager extends IInterface {
void unregisterTaskStackListener(ITaskStackListener listener) throws RuntimeException;
boolean removeTask(int taskId);
void moveRootTaskToDisplay(int taskId, int displayId) throws RuntimeException;
void moveStackToDisplay(int stackId, int displayId) throws RuntimeException;

abstract class Stub extends Binder implements IActivityTaskManager {
public static IActivityTaskManager asInterface(IBinder binder) {
Expand Down

0 comments on commit 101a2b7

Please sign in to comment.