[Android Software Development] lukakas:
How to port SONY Small Apps/Taskswitcher plugin Xperia Z1 Android 4.3 for CM10.1 or CM10.2
​

CyanogenMod 10.1 with Small Apps Z1 on my mango!​

Hello I'm [MENTION=4684483]lukakas[/MENTION].

I made this guide that will help you to mod your ROM for support fully Small Apps from Xperia Z1 4.3 (Include taskswitcher plugin mod). Works only for CM10.1/CM10.2 and maybe 4.2.2/4.3 based devices (Confirmed for working).

Small Apps Z1 4.3 is latest version of Sony, it bring us new features like:

Small Apps support.

Favorite list (Called taskswitcher plugin view) of small apps and "floatings" widgets on 'Recents Apps' (Taskswitcher).

Widget floating window supported. (Like if converted homescreen widgets to small apps).

Multiple windows by default from Z1, watch this vídeo: http://www.youtube.com/watch?v=PfspA0-YcYY

Latest features of small apps ported from Xperia Z1 with Android 4.3 version.

And much more to find.

Watch this video for looking these features working on CM10.1:​

[YOUTUBE]ZDuQW8S8AgY[/YOUTUBE]​

Information:

Let's go to mod:

Step 1 - Decompile android.policy.jar

And open smali\com\android\internal\policy\impl\PhoneWindowManager.smali

Find for method 'checkAddPermission' and replace all method to this lines below::

For CM11

.method public checkAddPermission(Landroid/view/WindowManager$LayoutParams;[I)I
.locals 4
.parameter "attrs"
.parameter "outAppOp"

.prologue
const/4 v2, 0x0

.line 1455
iget v1, p1, Landroid/view/WindowManager$LayoutParams;->type:I

.line 1457
.local v1, type:I
const/4 v3, -0x1

aput v3, p2, v2

.line 1459
const/16 v3, 0x7d0

if-lt v1, v3, :cond_0

const/16 v3, 0xbb7

if-le v1, v3, :cond_1

.line 1497
:cond_0
:goto_0
return v2

.line 1463
:cond_1
const/4 v0, 0x0

.line 1464
.local v0, permission:Ljava/lang/String;
sparse-switch v1, :sswitch_data_0

.line 1489
const-string v0, "android.permission.INTERNAL_SYSTEM_WINDOW"

.line 1491
:goto_1
:sswitch_0
if-eqz v0, :cond_0

.line 1492
iget-object v3, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mContext:Landroid/content/Context;

invoke-virtual {v3, v0}, Landroid/content/Context;->checkCallingOrSelfPermission(Ljava/lang/String;)I

move-result v3

if-eqz v3, :cond_0

.line 1494
const/4 v2, -0x8

goto :goto_0

.line 1481
:sswitch_1
const-string v0, "android.permission.SYSTEM_ALERT_WINDOW"

.line 1482
const/16 v3, 0x18

aput v3, p2, v2

goto :goto_1

.line 1486
:sswitch_2
const-string v0, "com.sony.smallapp.permission.SMALLAPP"

.line 1487
goto :goto_1

.line 1464
nop

:sswitch_data_0
.sparse-switch
0x7d2 -> :sswitch_1
0x7d3 -> :sswitch_1
0x7d5 -> :sswitch_0
0x7d6 -> :sswitch_1
0x7d7 -> :sswitch_1
0x7da -> :sswitch_1
0x7db -> :sswitch_0
0x7dd -> :sswitch_0
0x7e7 -> :sswitch_0
0x7ee -> :sswitch_0
0xbb5 -> :sswitch_2
0xbb6 -> :sswitch_2
.end sparse-switch
.end method

For CM10.2

.method public checkAddPermission(Landroid/view/WindowManager$LayoutParams;[I)I
.locals 4
.parameter "attrs"
.parameter "outAppOp"

.prologue
const/4 v2, 0x0

.line 1367
iget v1, p1, Landroid/view/WindowManager$LayoutParams;->type:I

.line 1369
.local v1, type:I
const/4 v3, -0x1

aput v3, p2, v2

.line 1371
const/16 v3, 0x7d0

if-lt v1, v3, :cond_0

const/16 v3, 0xbb7

if-le v1, v3, :cond_1

.line 1408
:cond_0
:goto_0
return v2

.line 1375
:cond_1
const/4 v0, 0x0

.line 1376
.local v0, permission:Ljava/lang/String;
sparse-switch v1, :sswitch_data_0

.line 1400
const-string v0, "android.permission.INTERNAL_SYSTEM_WINDOW"

.line 1402
:goto_1
:sswitch_0
if-eqz v0, :cond_0

.line 1403
iget-object v3, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mContext:Landroid/content/Context;

invoke-virtual {v3, v0}, Landroid/content/Context;->checkCallingOrSelfPermission(Ljava/lang/String;)I

move-result v3

if-eqz v3, :cond_0

.line 1405
const/4 v2, -0x8

goto :goto_0

.line 1392
:sswitch_1
const-string v0, "android.permission.SYSTEM_ALERT_WINDOW"

.line 1393
const/16 v3, 0x18

aput v3, p2, v2

goto :goto_1

.line 1397
:sswitch_2
const-string v0, "com.sony.smallapp.permission.SMALLAPP"

.line 1398
goto :goto_1

.line 1376
nop

:sswitch_data_0
.sparse-switch
0x7d2 -> :sswitch_1
0x7d3 -> :sswitch_1
0x7d5 -> :sswitch_0
0x7d6 -> :sswitch_1
0x7d7 -> :sswitch_1
0x7da -> :sswitch_1
0x7db -> :sswitch_0
0x7dd -> :sswitch_0
0x7e7 -> :sswitch_0
0xbb5 -> :sswitch_2
0xbb6 -> :sswitch_2
.end sparse-switch
.end method

For CM10.1

.method public checkAddPermission(Landroid/view/WindowManager$LayoutParams;)I
.locals 4
.parameter "attrs"

.prologue
const/4 v2, 0x0

.line 1315
iget v1, p1, Landroid/view/WindowManager$LayoutParams;->type:I

.line 1317
.local v1, type:I
const/16 v3, 0x7d0

if-lt v1, v3, :cond_0

const/16 v3, 0xbb7

if-le v1, v3, :cond_1

.line 1353
:cond_0
:goto_0
return v2

.line 1321
:cond_1
const/4 v0, 0x0

.line 1322
.local v0, permission:Ljava/lang/String;
sparse-switch v1, :sswitch_data_0

.line 1345
const-string v0, "android.permission.INTERNAL_SYSTEM_WINDOW"

.line 1347
:goto_1
:sswitch_0
if-eqz v0, :cond_0

.line 1348
iget-object v3, p0, Lcom/android/internal/policy/impl/PhoneWindowManager;->mContext:Landroid/content/Context;

invoke-virtual {v3, v0}, Landroid/content/Context;->checkCallingOrSelfPermission(Ljava/lang/String;)I

move-result v3

if-eqz v3, :cond_0

.line 1350
const/4 v2, -0x8

goto :goto_0

.line 1338
:sswitch_1
const-string v0, "android.permission.SYSTEM_ALERT_WINDOW"

.line 1339
goto :goto_1

.line 1342
:sswitch_2
const-string v0, "com.sony.smallapp.permission.SMALLAPP"

.line 1343
goto :goto_1

.line 1322
:sswitch_data_0
.sparse-switch
0x7d2 -> :sswitch_1
0x7d3 -> :sswitch_1
0x7d5 -> :sswitch_0
0x7d6 -> :sswitch_1
0x7d7 -> :sswitch_1
0x7da -> :sswitch_1
0x7db -> :sswitch_0
0x7dd -> :sswitch_0
0x7e7 -> :sswitch_0
0xbb5 -> :sswitch_2
0xbb6 -> :sswitch_2
.end sparse-switch
.end method

Save your modifications and recompile it.

Step 2 - Decompile framework.jar

Open folder smali/com/

For CM10.2

Paste 'Sony' folder (provided [URL=http://d-h.st/YUr]SmallApps_Z1-4.3Resources.zip - 16.98 KB[/URL] file attached in folder resources/framework)
Save your modifications and recompile it.

For CM10.1

Paste 'Sony' folder (provided [URL=http://d-h.st/jTp]SmallApps_Z1-4.2.2_Resources.zip - 17.71 KB[/URL] file attached in folder resources/framework)
Save your modifications and recompile it.

Step 3 - Decompile framework-res.apk

And open AndroidManifest.xml

Add these lines:

<permission android:name="com.sony.smallapp.permission.CONTROL_SMALLAPP" android:protectionLevel="system|signature" />
<permission android:label="@string/permlab_smallapp" android:name="com.sony.smallapp.permission.SMALLAPP" android:protectionLevel="dangerous" android:description="@string/permdesc_smallapp" />
<permission android:label="@string/permlab_taskSwitcherPluginView" android:name="com.sonymobile.permission.TASK_SWITCHER_PLUGIN_VIEW" android:protectionLevel="signatureOrSystem" android:description="@string/permdesc_taskSwitcherPluginView" />
<permission android:name="com.sonymobile.permission.ACCESS_BEACON_MANAGER" android:protectionLevel="system|signature" />

Like this marked in red lines:

<permission android:label="@string/permlab_serialPort" android:name="android.permission.SERIAL_PORT" android:protectionLevel="system|signature" android:description="@string/permdesc_serialPort" />
<permission android:label="@string/permlab_accessContentProvidersExternally" android:name="android.permission.ACCESS_CONTENT_PROVIDERS_EXTERNALLY" android:protectionLevel="signature" android:description="@string/permdesc_accessContentProvidersExternally" />
<permission android:label="@string/permlab_updateLock" android:name="android.permission.UPDATE_LOCK" android:protectionLevel="signatureOrSystem" android:description="@string/permdesc_updateLock" />
<uses-permission android:name="android.permission.CONFIRM_FULL_BACKUP" />
[COLOR="Red"]<permission android:name="com.sony.smallapp.permission.CONTROL_SMALLAPP" android:protectionLevel="system|signature" />
<permission android:label="@string/permlab_smallapp" android:name="com.sony.smallapp.permission.SMALLAPP" android:protectionLevel="dangerous" android:description="@string/permdesc_smallapp" />
<permission android:label="@string/permlab_taskSwitcherPluginView" android:name="com.sonymobile.permission.TASK_SWITCHER_PLUGIN_VIEW" android:protectionLevel="signatureOrSystem" android:description="@string/permdesc_taskSwitcherPluginView" />
<permission android:name="com.sonymobile.permission.ACCESS_BEACON_MANAGER" android:protectionLevel="system|signature" />[/COLOR]
<application android:label="@string/android_system_label" android:icon="@drawable/ic_launcher_android" android:allowClearUserData="false" android:hasCode="false" android:persistent="true" android:process="system" android:backupAgent="com.android.server.SystemBackupAgent" android:killAfterRestore="false" android:supportsRtl="true">
<activity android:theme="@style/Theme.Holo.Dialog.Alert" android:name="com.android.internal.app.ChooserActivity" android:multiprocess="true" android:excludeFromRecents="true" android:finishOnCloseSystemDialogs="true">
<intent-filter>
<action android:name="android.intent.action.CHOOSER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:theme="@style/Theme.Holo.Dialog" android:label="@string/heavy_weight_switcher_title" android:name="com.android.internal.app.HeavyWeightSwitcherActivity" android:process=":ui" android:excludeFromRecents="true" android:finishOnCloseSystemDialogs="true" />

Then, go to res/values/strings.xml and add these lines at the end:

<string name="permlab_taskSwitcherPluginView">Provide plugin-view to the task-switcher</string>
<string name="permdesc_taskSwitcherPluginView">Allows the application to provide a plugin-view to the task-switcher.</string>
<string name="permlab_smallapp">Small application overlay</string>
<string name="permdesc_smallapp">Allows running movable small applications on top of other applications.</string>

Save your modifications and recompile it.

Now we go to most difficult part: Porting TaskSwitcher in SystemUI.apk.