Skip to content

Commit

Permalink
base: Add support for LMOFreeform service
Browse files Browse the repository at this point in the history
Change-Id: I03ebd2e0e175f91fbc83fb9221724d7be5daf7ca

services: Add LMOFreeform system service

Change-Id: Icb3933846fc38f7fe1679e7f1fd916c2c137671d
  • Loading branch information
adithya2306 authored and fazilsheik96 committed Feb 27, 2025
1 parent 5a5a58b commit 5a72852
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ filegroup {
":storaged_aidl",
":vold_aidl",
":deviceproductinfoconstants_aidl",
":lmofreeform_aidl",

// For the generated R.java and Manifest.java
":framework-res{.aapt.srcjar}",
Expand Down
15 changes: 15 additions & 0 deletions core/java/android/hardware/display/DisplayManagerInternal.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@
import android.hardware.SensorManager;
import android.hardware.input.HostUsiVersion;
import android.os.Handler;
import android.os.IBinder;
import android.os.PowerManager;
import android.util.IntArray;
import android.util.SparseArray;
import android.view.Display;
import android.view.DisplayInfo;
import android.view.Surface;
import android.view.SurfaceControl;
import android.view.SurfaceControl.RefreshRateRange;
import android.view.SurfaceControl.Transaction;
import android.window.DisplayWindowPolicyController;
import android.window.ScreenCapture;

import com.libremobileos.freeform.ILMOFreeformDisplayCallback;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
Expand Down Expand Up @@ -430,6 +434,17 @@ public abstract RefreshRateRange getRefreshRateForDisplayAndSensor(
*/
public abstract IntArray getDisplayGroupIds();

// LMOFreeform
public abstract void createFreeformLocked(String name, ILMOFreeformDisplayCallback callback,
int width, int height, int densityDpi, boolean secure, boolean ownContentOnly,
boolean shouldShowSystemDecorations, Surface surface, float refreshRate,
long presentationDeadlineNanos);

public abstract void resizeFreeform(IBinder appToken, int width, int height,
int densityDpi);

public abstract void releaseFreeform(IBinder appToken);

/**
* Called upon presentation started/ended on the display.
* @param displayId the id of the display where presentation started.
Expand Down
4 changes: 4 additions & 0 deletions core/res/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,10 @@
android:permissionGroup="android.permission-group.UNDEFINED"
android:protectionLevel="signature|appop|preinstalled" />

<!-- @hide -->
<permission android:name="com.libremobileos.permission.START_FREEFORM"
android:protectionLevel="signature|privileged" />

<!-- Allows an application to modify and delete media files on this device or any connected
storage device without user confirmation. Applications must already be granted the
{@link #READ_EXTERNAL_STORAGE} or {@link #MANAGE_EXTERNAL_STORAGE}} permissions for this
Expand Down
1 change: 1 addition & 0 deletions data/etc/com.android.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@
<permission name="android.permission.LIST_ENABLED_CREDENTIAL_PROVIDERS" />
<permission name="android.permission.SATELLITE_COMMUNICATION" />
<permission name="android.permission.READ_SYSTEM_GRAMMATICAL_GENDER" />
<permission name="com.libremobileos.permission.START_FREEFORM" />
</privapp-permissions>
</permissions>
1 change: 1 addition & 0 deletions services/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ java_library {
"service-blobstore",
"service-jobscheduler",
"android.hidl.base-V1.0-java",
"lmofreeform-server",
],

libs: [
Expand Down
1 change: 1 addition & 0 deletions services/core/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ java_library_static {
":display-device-config",
":display-layout-config",
":device-state-config",
":lmofreeform-display-adapter-java",
"java/com/android/server/EventLogTags.logtags",
"java/com/android/server/am/EventLogTags.logtags",
"java/com/android/server/wm/EventLogTags.logtags",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@
import com.android.server.wm.SurfaceAnimationThread;
import com.android.server.wm.WindowManagerInternal;

import com.libremobileos.freeform.ILMOFreeformDisplayCallback;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
Expand Down Expand Up @@ -517,6 +519,8 @@ public synchronized void requestDisplayState(int displayId, int state, float bri
private final boolean mExtraDisplayEventLogging;
private final String mExtraDisplayLoggingPackageName;

private LMOFreeformDisplayAdapter mFreeformDisplayAdapter;

private final BroadcastReceiver mIdleModeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Expand Down Expand Up @@ -1970,6 +1974,7 @@ private void registerAdditionalDisplayAdapters() {
if (shouldRegisterNonEssentialDisplayAdaptersLocked()) {
registerOverlayDisplayAdapterLocked();
registerWifiDisplayAdapterLocked();
registerFreeformDisplayAdapterLocked();
}
}
}
Expand All @@ -1990,6 +1995,13 @@ private void registerWifiDisplayAdapterLocked() {
}
}

private void registerFreeformDisplayAdapterLocked() {
mFreeformDisplayAdapter = new LMOFreeformDisplayAdapter(
mSyncRoot, mContext, mHandler, mDisplayDeviceRepo, mLogicalDisplayMapper,
mUiHandler, mFlags);
registerDisplayAdapterLocked(mFreeformDisplayAdapter);
}

private boolean shouldRegisterNonEssentialDisplayAdaptersLocked() {
// In safe mode, we disable non-essential display adapters to give the user
// an opportunity to fix broken settings or other problems that might affect
Expand Down Expand Up @@ -5150,6 +5162,23 @@ public DisplayManagerInternal.DisplayOffloadSession registerDisplayOffloader(
public void onPresentation(int displayId, boolean isShown) {
mExternalDisplayPolicy.onPresentation(displayId, isShown);
}

public void createFreeformLocked(String name, ILMOFreeformDisplayCallback callback,
int width, int height, int densityDpi, boolean secure, boolean ownContentOnly,
boolean shouldShowSystemDecorations, Surface surface, float refreshRate,
long presentationDeadlineNanos) {
mFreeformDisplayAdapter.createFreeformLocked(name, callback, width, height, densityDpi,
secure, ownContentOnly, shouldShowSystemDecorations, surface, refreshRate,
presentationDeadlineNanos);
}

public void resizeFreeform(IBinder appToken, int width, int height, int densityDpi) {
mFreeformDisplayAdapter.resizeFreeform(appToken, width, height, densityDpi);
}

public void releaseFreeform(IBinder appToken) {
mFreeformDisplayAdapter.releaseFreeform(appToken);
}
}

class DesiredDisplayModeSpecsObserver
Expand Down
5 changes: 5 additions & 0 deletions services/java/com/android/server/SystemServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@
import com.android.server.wm.WindowManagerService;
import com.android.server.lineage.health.HealthInterfaceService;
import com.android.server.lineage.LineageGlobalActionsService;
import com.libremobileos.server.display.LMOFreeformSystemService;

import dalvik.system.VMRuntime;
import dalvik.system.PathClassLoader;
Expand Down Expand Up @@ -1736,6 +1737,10 @@ private void startOtherServices(@NonNull TimingsTraceAndSlog t) {
mSystemServiceManager.startService(LineageGlobalActionsService.class);
t.traceEnd();

t.traceBegin("LMOFreeformSystemService");
mSystemServiceManager.startService(LMOFreeformSystemService.class);
t.traceEnd();

} catch (Throwable e) {
Slog.e("System", "******************************************");
Slog.e("System", "************ Failure starting core service");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2023-2024 LibreMobileOS Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.libremobileos.server.display;

import android.content.Context;
import android.hardware.display.DisplayManagerInternal;
import android.util.Slog;

import com.android.server.SystemService;

import com.libremobileos.freeform.server.LMOFreeformService;
import com.libremobileos.freeform.server.LMOFreeformServiceHolder;
import com.libremobileos.freeform.server.LMOFreeformUIService;

public class LMOFreeformSystemService extends SystemService {

private static final String TAG = "LMOFreeformSystemService";

public LMOFreeformSystemService(Context context) {
super(context);
}

@Override
public void onStart() {
// noop
}

@Override
public void onBootPhase(@BootPhase int phase) {
if (phase != PHASE_ACTIVITY_MANAGER_READY || isSafeMode()) return;

Slog.d(TAG, "PHASE_ACTIVITY_MANAGER_READY, going to init!");

DisplayManagerInternal displayManager = getLocalService(DisplayManagerInternal.class);
if (displayManager == null) {
Slog.e(TAG, "Cannot init: DisplayManagerInternal is null!");
return;
}

LMOFreeformService service = new LMOFreeformService(displayManager);
LMOFreeformUIService uiService =
new LMOFreeformUIService(getContext(), displayManager, service);
LMOFreeformServiceHolder.init(uiService, service);
}
}

0 comments on commit 5a72852

Please sign in to comment.