Skip to content
Snippets Groups Projects
Commit edf4265e authored by Nick's avatar Nick :v:
Browse files

VncFlinger spring cleanup

Change-Id: I9191b649f326c8c2d744643856a746a1ef699d85
parent 161a16e8
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:tools="http://schemas.android.com/tools"
android:sharedUserId="android.uid.system"
package="com.libremobileos.vncflinger">
<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.CAPTURE_SECURE_VIDEO_OUTPUT"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.ADD_TRUSTED_DISPLAY"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.ROTATE_SURFACE_FLINGER"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.READ_CLIPBOARD_IN_BACKGROUND"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT"
tools:ignore="ProtectedPermissions" />
<permission android:name="com.libremobileos.vncflinger.USE_VNC"
android:protectionLevel="signature|privileged" />
<application
android:label="@string/app_name"
android:sharedUserId="android.uid.system"
android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault.DayNight"
tools:ignore="MissingApplicationIcon">
<service
android:name=".VncFlinger"
android:configChanges="density|fontScale|keyboard|keyboardHidden|layoutDirection|locale|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode"
android:exported="true"
tools:ignore="ExportedService" />
</application>
<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.CAPTURE_SECURE_VIDEO_OUTPUT"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.ADD_TRUSTED_DISPLAY"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.ROTATE_SURFACE_FLINGER"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.READ_CLIPBOARD_IN_BACKGROUND"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT"
tools:ignore="ProtectedPermissions" />
<application
android:persistent="true"
android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault.DayNight"
tools:ignore="MissingApplicationIcon">
<service
android:name=".VncFlinger"
android:configChanges="density|fontScale|keyboard|keyboardHidden|layoutDirection|locale|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode"
android:exported="true"
android:permission="com.libremobileos.vncflinger.USE_VNC" />
</application>
</manifest>
......@@ -32,8 +32,6 @@ public class VncFlinger extends Service {
System.loadLibrary("jni_vncflinger");
System.loadLibrary("jni_audiostreamer");
}
public final int ONGOING_NOTIFICATION_ID = 5;
public final String CHANNEL_ID = "services";
public final String LOG_TAG = "VNCFlinger";
public boolean mMirrorInternal = false;
......@@ -191,27 +189,6 @@ public class VncFlinger extends Service {
inputManager.setForceNullCursor(false);
}
NotificationManager notificationManager = getSystemService(NotificationManager.class);
if (notificationManager.getNotificationChannel(CHANNEL_ID) == null) {
CharSequence name = getString(R.string.channel_name);
String description = getString(R.string.channel_description);
int importance = NotificationManager.IMPORTANCE_LOW;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
channel.setBlockable(true);
notificationManager.createNotificationChannel(channel);
}
Notification.Builder notification = new Notification.Builder(this, CHANNEL_ID)
.setContentTitle(getText(R.string.notification_title))
.setContentText(getString(R.string.notification_message, getText(R.string.app_name)))
.setSmallIcon(R.drawable.ic_desktop);
if (mIntentEnable) {
Intent i = new Intent();
i.setComponent(new ComponentName(mIntentPkg, mIntentComponent));
notification.setContentIntent(PendingIntent.getActivity(mContext, 0, i, PendingIntent.FLAG_IMMUTABLE));
}
startForeground(ONGOING_NOTIFICATION_ID, notification.build());
mIsRunning = true;
return START_NOT_STICKY;
}
......@@ -280,7 +257,7 @@ public class VncFlinger extends Service {
if ((exitCode = initializeVncFlinger(mVNCFlingerArgs)) == 0) {
doSetDisplayProps();
if ((exitCode = startService()) == 0) {
stopForeground(STOP_FOREGROUND_REMOVE);
stopSelf();
return;
}
}
......@@ -297,7 +274,7 @@ public class VncFlinger extends Service {
private void doSetDisplayProps() {
setDisplayProps(mMirrorInternal ? -1 : mWidth, mMirrorInternal ? -1 : mHeight,
mMirrorInternal ? -1 : mDisplay.getDisplay().getRotation() * 90, mMirrorInternal ? 0 : -1,
mEmulateTouch, mUseRelativeInput);
mEmulateTouch, mUseRelativeInput, mSupportClipboard);
}
// used from native
......@@ -328,7 +305,8 @@ public class VncFlinger extends Service {
// used from native
private void setServerClipboard(String text) {
if (!mSupportClipboard)
return;
throw new IllegalStateException();
ClipData clip = ClipData.newPlainText("VNCFlinger", text);
mClipboard.setPrimaryClip(clip);
}
......@@ -336,7 +314,7 @@ public class VncFlinger extends Service {
// used from native
private String getServerClipboard() {
if (!mSupportClipboard)
return "";
throw new IllegalStateException();
String text = "";
if (mClipboard.hasPrimaryClip() && mClipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) {
......@@ -355,7 +333,7 @@ public class VncFlinger extends Service {
private native int initializeVncFlinger(String[] commandLineArgs);
private native void setDisplayProps(int width, int height, int rotation, int layerId, boolean emulateTouch, boolean useRelativeInput);
private native void setDisplayProps(int width, int height, int rotation, int layerId, boolean emulateTouch, boolean useRelativeInput, boolean supportClipboard);
private native int startService();
......
<vector android:height="24dp" android:tint="?android:attr/colorControlNormal"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M20,3H4C2.9,3 2,3.9 2,5v11c0,1.1 0.9,2 2,2h6l-2,2v1h8v-1l-2,-2h6c1.1,0 2,-0.9 2,-2V5C22,3.9 21.1,3 20,3"/>
</vector>
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<string name="app_name">VNC services</string>
<string name="channel_name">Service notification</string>
<string name="channel_description">You may block this notification category.</string>
<string name="notification_title">VNC is enabled</string>
<string name="notification_message">\"%s\" is currently running</string>
</resources>
\ No newline at end of file
......@@ -12,7 +12,7 @@ cc_library {
cflags: [
"-DVNCFLINGER_VERSION=1.0",
//"-DLOG_NDEBUG=0",
//"-DDESKTOP_NAME=VncDesktop",
"-DDESKTOP_NAME=DesktopMode",
"-Ofast",
"-Werror",
"-fexceptions",
......
......@@ -75,6 +75,7 @@ void AndroidDesktop::stop() {
}
void AndroidDesktop::handleClipboardRequest() {
if (!clipboard) return;
const char* data = runJniCallbackGetClipboard();
if (strlen(data)) mServer->sendClipboardData(data);
}
......@@ -84,6 +85,7 @@ void AndroidDesktop::handleClipboardAnnounce(bool available) {
}
void AndroidDesktop::handleClipboardData(const char* data) {
if (!clipboard) return;
runJniCallbackSetClipboard(data);
}
......@@ -97,7 +99,7 @@ void AndroidDesktop::processClipboard() {
return;
clipboardChanged = false;
if (mServer) mServer->announceClipboard(true);
if (mServer) mServer->announceClipboard(clipboard);
}
void AndroidDesktop::setCursor(uint32_t width, uint32_t height, int hotX, int hotY,
......@@ -118,12 +120,12 @@ void AndroidDesktop::processCursor() {
}
void AndroidDesktop::processFrames() {
if (!frameChanged)
return;
if (mVirtualDisplay == NULL)
return;
if (mPixels == NULL)
return;
if (!frameChanged)
return;
frameChanged = false;
Mutex::Autolock _l(mLock);
......@@ -251,8 +253,6 @@ status_t AndroidDesktop::updateDisplayInfo(bool force) {
return err;
}
mDisplayState = tempDisplayState.orientation;
mLayerId = 0; // internal display constant id
} else if (_width > 0 && _height > 0 && _rotation > -1) {
mDisplayMode = ui::Size(_width, _height);
mDisplayState = _rotation == 270 ? ui::ROTATION_270 : (_rotation == 180 ? ui::ROTATION_180 : (_rotation == 90 ? ui::ROTATION_90 : ui::ROTATION_0));
......
......@@ -65,7 +65,7 @@ class AndroidDesktop : public rfb::SDesktop,
int32_t mLayerId = -1;
sp<VirtualDisplay> mVirtualDisplay;
int32_t _width = 1, _height = 1, _rotation = 0;
bool touch = false, relative = false;
bool touch = false, relative = false, clipboard = false;
private:
virtual void notify();
......
......@@ -97,7 +97,6 @@ void AndroidPixelBuffer::setWindowSize(uint32_t width, uint32_t height) {
void AndroidPixelBuffer::setDisplayInfo(ui::Size* mode, ui::Rotation* state, bool force) {
bool rotated = isDisplayRotated(*state);
setBufferRotation(rotated);
uint32_t w = rotated ? mode->height : mode->width;
uint32_t h = rotated ? mode->width : mode->height;
......@@ -107,7 +106,10 @@ void AndroidPixelBuffer::setDisplayInfo(ui::Size* mode, ui::Rotation* state, boo
h);
mSourceWidth = w;
mSourceHeight = h;
mRotated = rotated;
updateBufferSize(true);
} else {
setBufferRotation(rotated);
}
}
......@@ -118,4 +120,5 @@ Rect AndroidPixelBuffer::getSourceRect() {
void AndroidPixelBuffer::reset() {
mSourceWidth = 0;
mSourceHeight = 0;
mRotated = false;
}
......@@ -53,11 +53,11 @@ VirtualDisplay::VirtualDisplay(ui::Size* mode, ui::Rotation* state,
mCpuConsumer->setFrameAvailableListener(listener);
if (mLayerId >= 0) {
mDisplayToken = SurfaceComposerClient::createDisplay(String8("VNC-VirtualDisplay"), false); //TODO: figure out why sf doesnt let us use secure display, we are system
mDisplayToken = SurfaceComposerClient::createDisplay(String8("VNC-VirtualDisplay"), true);
SurfaceComposerClient::Transaction t;
t.setDisplaySurface(mDisplayToken, mProducer);
t.setDisplayProjection(mDisplayToken, *state, mSourceRect, displayRect);
t.setDisplayProjection(mDisplayToken, ui::ROTATION_0, mSourceRect, displayRect);
t.setDisplayLayerStack(mDisplayToken, android::ui::LayerStack::fromValue(mLayerId));
t.apply();
}
......
......@@ -178,12 +178,12 @@ extern "C" void Java_com_libremobileos_vncflinger_VncFlinger_quit(JNIEnv *env, j
extern "C" void Java_com_libremobileos_vncflinger_VncFlinger_setDisplayProps(JNIEnv *env,
jobject thiz, jint w,
jint h, jint rotation, jint layerId, jboolean touch,
jboolean relative) {
jboolean relative, jboolean clipboard) {
if (desktop == NULL) {
ALOGW("setDisplayProps: desktop == NULL");
return;
}
desktop->_width = w; desktop->_height = h; desktop->_rotation = rotation; desktop->mLayerId = layerId; desktop->touch = touch; desktop->relative = relative;
desktop->_width = w; desktop->_height = h; desktop->_rotation = rotation; desktop->mLayerId = layerId; desktop->touch = touch; desktop->relative = relative; desktop->clipboard == clipboard;
}
extern "C" void Java_com_libremobileos_vncflinger_VncFlinger_notifyServerClipboardChanged(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment