38
Les nouveautés d’Android Nougat Paris Android User Group Extrait du meetup septembre

Android Nougat (7.0) : Nouveautés Android TV et Direct Boot

Embed Size (px)

Citation preview

Les nouveautés

d’Android Nougat

Paris Android User Group Extrait du meetup septembre

Edouard MarquezDéveloppeur Android Freelance

2

@g123k

+EdouardMarquez

www.edouard-marquez.me

Android TVEdouard Marquez

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Android TV : Qu’est-ce que le picture in picture (PIP) ?

4

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Android TV : Supporter le picture in picture (Android Manifest)

5

<activity

android:name=".MyActivity" android:resizeableActivity="true" android:supportsPictureInPicture="true" android:configChanges="screenSize|smallestScreenSize|

screenLayout|orientation" />

Mettre le launchMode en singleTask est recommandé

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Android TV : Supporter le picture in picture (bouton)

6

if (supportsPIP(context)) {

adapter.add( new PlaybackControlsRow.PictureInPictureAction(context));

}

boolean supportsPIP(Context context) {

return BuildCompat.isAtLeastN() && context.getPackageManager().hasSystemFeature( PackageManager.FEATURE_PICTURE_IN_PICTURE);

}

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Android TV : Supporter le picture in picture (activer le mode)

7

public void onActionClicked(Action action) {

if (action.getId() == R.id.lb_control_picture_in_picture) {

getActivity().enterPictureInPictureMode(); return;

}

// ....

}

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Android TV : Picture in picture

8

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Android TV : Cacher les composants en mode picture in picture

9

void onPictureInPictureChanged(boolean inPictureInPicture) {

if (inPictureInPicture) {

uiControls.setVisibility(View.INVISIBLE);

} else {

uiControls.setVisibility(View.VISIBLE);

}

}

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Android TV : Gestion du lifecycle avec le picture in picture

10

public void onPause() {

super.onPause();

if (!inPictureInPicture() && videoView.isPlaying()) {

if (!requestVisibleBehind(true)) {

playPause(false);

} else {

requestVisibleBehind(false);

}

}

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Android TV - Picture in picture : Exemple de code

11

Exemple de code

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Android TV : Enregistrement des chaînes TV

12

Direct BootEdouard Marquez

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Etre notifié du démarrage du terminal

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<receiver android:name=".BootBroadcastReceiver"

<intent-filter>

<action android:name="android.intent.action.BOOT_COMPLETED" />

</intent-filter>

</receiver>

14

Intent relatif au démarrage du terminal

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

L’application doit avoir été lancée une première fois avant de recevoir l’Intent

Depuis Android 3.1

15

Intent relatif au démarrage du terminal

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

3.0 (Honeycomb) Février 2011

Support du chiffrement

Full Disk Encryption (FDE)

4.4 (KitKat) Novembre 2013

Utilisation de scrypt

Sécurité renforcée

7.0 (Nougat) Août 2016

Nouveau type de chiffrement

File-Based Encryption (FBE)

5.0 (Lollipop) Novembre 2014

Diverses améliorations

Chiffrement sans mot de passe, support schéma…

16

Android : Evolution du chiffrement

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Mieux comprendre

le chiffrement

5.0 (Lollipop) Novembre 2014

Chiffrement obligatoire

… puis non

6.0 (Marshmallow) Septembre 2015

Chiffrement (vraiment) obligatoire

17

Android : Evolution du chiffrement

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

— Seuls des mots de passe et PIN peuvent être utilisés

— La demande au démarrage est bloquante

Android 3.0 - Android 4.4

— Possibilité d’utiliser des schémas

— Le démarrage sécurisé devient optionnel

Depuis Android 5.0

18

Android : Evolution du chiffrement

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

— Aucune application tierce n’est exécutée

— Bloque le lancement du terminal

Démarrage sécurisé

19

Android : Evolution du chiffrement

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Seuls les terminaux

sous Android 7.0 peuvent en bénéficier

Depuis Nougat

Le terminal doit être chiffré

Données chiffrées

Le chiffrement doit être “basé sur un fichier”

File-based encryption

20

Comment obtenir Direct Boot ?

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Android Manifest

Ajouter android:directBootAware uniquement sur les

receivers / services / providers qui seront accessibles

au démarrage

L’attribut n’apporte rien sur les Activity, car il faut au préalable

déverrouiller le terminal

Un nouvel Intent est envoyé lors du “direct boot”

<receiver android:name=".BootBroadcastReceiver"

android:directBootAware="true"

android:exported="true">

<intent-filter>

<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />

<action android:name="android.intent.action.BOOT_COMPLETED" />

</intent-filter>

</receiver>

21

Implémenter Direct Boot

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Application “système”

Il est possible de mettre l’attribut sur le tag application, mais il ne prendra

effet que sur les applications “système”

<application

android:allowBackup="true"

android:label="@string/app_name"

android:icon="@mipmap/ic_launcher"

android:theme="@style/Theme.AppCompat.Light"

android:directBootAware="true">

22

Implémenter Direct Boot

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Stockage disponible uniquement après le premier déverrouillage

Credential Encrypted (CE) storage

Stockage disponible avant et après le premier déverrouillage

Device Encrypted (DE) storage

23

Les deux types de stockage

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Utiliser le stockage DE

Il faut récupérer un Context différent

Deux méthodes permettent de déplacer facilement les préférences

et bases de données dans leur globalité

Context context = ContextCompat.createDeviceProtectedStorageContext(srcContext);

ContextCompat.isDeviceProtectedStorage(context);

context.moveDatabaseFrom(srcContext, "dbName");

context.moveSharedPreferencesFrom(srcContext, "prefName");

24

Utiliser le stockage DE (accessible avant le déverrouillage)

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Application “système”

Il est possible d’ajouter un attribut le tag application afin que seul le

stockage “DE” soit utilisé

<application

android:allowBackup="true"

android:label="@string/app_name"

android:icon="@mipmap/ic_launcher"

android:theme="@style/Theme.AppCompat.Light"

android:directBootAware="true"

android:defaultToDeviceProtectedStorage="true">

25

Utiliser le stockage DE (accessible avant le déverrouillage)

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Tester Direct Boot

— Paramètres -> Options pour les développeurs -> Convertir en chiffrement basé sur un fichier

— adb reboot bootloaderfastboot --wipe-and-use-fbe

Emulation de Direct Boot

— adb shell sm set-emulate-fbe true — adb shell sm set-emulate-fbe false

26

Tester Direct Boot

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

android.intent.action.BOOT_COMPLETED android.intent.action.USER_PRESENT

27

L’évolution des Intent envoyés : avant Nougat

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

android.intent.action.LOCKED_BOOT_COMPLETED android.intent.action.USER_PRESENT

puis

android.intent.action.BOOT_COMPLETED

android.intent.action.ACTION_USER_UNLOCKED

28

L’évolution des Intent envoyés : avec Nougat et sans Direct Boot

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

android.intent.action.LOCKED_BOOT_COMPLETEDandroid.intent.action.BOOT_COMPLETED

android.intent.action.ACTION_USER_UNLOCKED

puis

android.intent.action.USER_PRESENT

29

L’évolution des Intent envoyés : avec Nougat et Direct Boot

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 630

Direct Boot : juste un dernier slide

— Chaque utilisateur possède ses propres clés

— Une pour le DE, l’autre pour CE

Support multi-utilisateur Exemple de code

UserManagerCompat.

isUserUnlocked(context));

Déverrouillé ?

Mais aussi...Edouard Marquez

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Raccourci vers les paramètres

32

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Raccourci vers les paramètres

33

Paramètres

Dans l’AndroidManifest, spécifier un Intent-Filter particulier

Afin d’éviter que d’autres applications puissent ouvrir cette

Activité, on peut limiter à une permission

Il n’est pas nécessaire que l’Activité soit exportée

<activity android:name=".MyActivity" android:permission="android.permission.WRITE_SECURE_SETTINGS">

<intent-filter>

<action android:name="android.intent.action.APPLICATION_PREFERENCES"/> <category android:name="android.intent.category.DEFAULT"/>

</intent-filter>

</activity>

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Résolution des langues

34

Default (en)

fr_BE

en_UK es_ES

de_DE ru_RU

fr_FR

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Résolution des langues (pre-Nougat)

35

fr_FR existe-il ?

Non juste fr_BE fr existe-il ? Non

Valeur par défaut (en)

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Résolution des langues (depuis Nougat)

36

fr_FR existe-il ?

Non juste fr_BE fr existe-il ?

NonExiste-t-il

un autre type de fr ?

Oui fr_BE

Les nouveautés d’Android Nougat (7.0) Paris Android User Group (bit.ly/paugand)

PARTIE 1 PARTIE 2 PARTIE 3 PARTIE 4 PARTIE 5 PARTIE 6

Langues multiples

37

Récupérer les différentes langues LocaleList.getDefault()

Support de ICU4J

Merci ! Questions ?

@g123k +EdouardMarquez