Skip to content

Commit

Permalink
Version 3.2.2
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 9ed8ac6acdf02b99fd5ff7166c59e104e19ad69b
  • Loading branch information
Interfaced authored and l1bbcsg committed Feb 3, 2020
1 parent 4f1dccc commit 540a210
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 117 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Changelog

## 3.1.0 (23.01.2020)
## 3.2.2 (03.02.2020)
* Support ZombieBox 2.6
* Better logging and output

## 3.2.1 (23.01.2020)
* Implement `setPlaybackRate`, `getPlaybackRate` and `EVENT_RATE_CHANGE` on `StatefulVideo`.
* Fail to `ERROR` state when no audio and video tracks can be played in current media file, particularly when they are DRM protected and proper `DRMClient` was not attached.

## 3.1.0 (16.01.2020)
## 3.2.0 (16.01.2020)
* Implement `StatefulVideo` model with PlayReady DRM support.
* Update ExoPlayer to 2.11.1 and other native components to their newest versions.

Expand Down
71 changes: 35 additions & 36 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ const fse = require('fs-extra');
const klaw = require('klaw');
const path = require('path');
const sharp = require('sharp');
const chalk = require('chalk');
const {AbstractPlatform, Application} = require('zombiebox');
const {AbstractPlatform, Application, logger: zbLogger} = require('zombiebox');

const logger = zbLogger.createChild('Android');


/**
Expand Down Expand Up @@ -76,7 +77,7 @@ class PlatformAndroid extends AbstractPlatform {
/**
* @override
*/
async buildApp(application, distDir) {
async pack(application, distDir) {
/**
* @param {number} len
* @return {string}
Expand All @@ -92,26 +93,26 @@ class PlatformAndroid extends AbstractPlatform {
const buildDir = path.join(distDir, 'src');

if (config.storeRelease) {
console.warn(chalk.yellow('Building unsigned release apk. It will not install unless signed.'));
logger.warn('Building unsigned release apk. It will not install unless signed.');

if (config.webViewDebug) {
console.warn(chalk.red('Building release with debug enabled'));
logger.warn('Building release with debug enabled');
}
}

if (!config.namespace) {
config.namespace = buildConfig.project.name;
console.warn(chalk.yellow(`Namespace not set, using "${config.namespace}"`));
logger.warn(`Namespace not set, using "${config.namespace}"`);
}

if (config.namespace.startsWith('test')) {
config.namespace = createRandomString();
console.warn(chalk.yellow(`Namespace could not start with "test", using ${config.namespace}`));
logger.warn(`Namespace could not start with "test", using ${config.namespace}`);
}

if (!config.versionName) {
config.versionName = application.getAppVersion();
console.warn(chalk.yellow(`Version name not set, using "${config.versionName}"`));
logger.warn(`Version name not set, using "${config.versionName}"`);
}

if (!config.versionCode && config.storeRelease) {
Expand All @@ -120,25 +121,24 @@ class PlatformAndroid extends AbstractPlatform {

if (!config.appId) {
if (config.storeRelease) {
console.error(chalk.red(`Application id not set`));
return Promise.reject();
throw new Error(`Application id is required for store release`);
}

config.appId = `com.zombiebox.${config.namespace}.${createRandomString()}`;
console.warn(chalk.yellow(`Application id not set, using "${config.appId}"`));
logger.warn(`Application id not set, using "${config.appId}"`);
}


logger.debug(`Cleaning ${buildDir}`);
await fse.emptyDir(buildDir);
await this._cloneSources(buildDir);
await this._applyBuildConfig(config, buildDir);
await this._copyResources(application, config, buildDir);
await this._markDebugBuild(config, buildDir);
const zbBuildWarnings = await this._compileZbApplication(application, distDir, config, buildDir);
await this._copyZbApplication(config, distDir, buildDir);
await this._compileApk(config, buildDir, config.namespace);
await this._copyApk(config, buildDir, distDir);
const apkPath = await this._copyApk(config, buildDir, distDir);

return zbBuildWarnings;
logger.output(`apk assembled: ${apkPath}`);
}

/**
Expand Down Expand Up @@ -178,7 +178,9 @@ class PlatformAndroid extends AbstractPlatform {
}
}

return `${config.namespace} {\n\t${properties.join('\n\t')}\n}`;
const flavor = `${config.namespace} {\n\t${properties.join('\n\t')}\n}`;
logger.debug(`Application flavor: \n${flavor}`);
return flavor;
}

/**
Expand Down Expand Up @@ -206,7 +208,7 @@ class PlatformAndroid extends AbstractPlatform {
*/
async _copyResources(application, config, buildDir) {
if (!config.resPath) {
console.warn(chalk.yellow('No resources set, will use default zb resources'));
logger.warn('No resources set, will use default zb resources');
return;
}

Expand All @@ -219,7 +221,7 @@ class PlatformAndroid extends AbstractPlatform {
const bannerPath = path.join(resPath, 'drawable', 'banner.png');

if (!await fse.pathExists(bannerPath)) {
console.warn(chalk.yellow('Banner image is not set. Will fall back to zb image'));
logger.warn('Banner image is not set. Will fall back to zb image');

const fallbackBanner = path.join(buildDir, 'app', 'src', 'main', 'res', 'drawable', 'banner.png');
const targetBannerPath = path.join(targetResPath, 'drawable', 'banner.png');
Expand All @@ -228,27 +230,19 @@ class PlatformAndroid extends AbstractPlatform {
}

/**
* @param {Application} application
* @param {string} distDir
* @param {Object} config
* @param {string} distDir
* @param {string} buildDir
* @return {Promise}
* @protected
*/
async _compileZbApplication(application, distDir, config, buildDir) {
let zbAppPath;
async _copyZbApplication(config, distDir, buildDir) {
if (config.useBundledHTML) {
zbAppPath = path.join(buildDir, 'app', 'src', config.namespace, 'assets', 'html', 'index.html');
} else {
zbAppPath = path.join(buildDir, 'index.html');
const zbAppPath = path.join(distDir, 'index.html');
const distAppPath = path.join(buildDir, 'app', 'src', config.namespace, 'assets', 'html', 'index.html');
await fse.ensureDir(path.dirname(distAppPath));
await fse.copy(zbAppPath, distAppPath);
}

const buildHelper = application.getBuildHelper();

await fse.ensureDir(path.dirname(zbAppPath));
const warnings = await buildHelper.writeIndexHTML(zbAppPath);
await buildHelper.copyStaticFiles(distDir);
return warnings;
}

/**
Expand All @@ -263,6 +257,7 @@ class PlatformAndroid extends AbstractPlatform {
return;
}

logger.verbose(`Applying debug overlay to app icon`);
const overlay = path.join(buildDir, 'app', 'src', 'main', 'res', 'drawable', 'debug.png');
const baseResourcesPath = path.join(buildDir, 'app', 'src', config.namespace, 'res');

Expand Down Expand Up @@ -301,12 +296,12 @@ class PlatformAndroid extends AbstractPlatform {

const buildType = config.storeRelease ? 'Release' : 'Debug';

console.log(chalk.green(`Compiling ${flavor} ${buildType} apk`));
logger.info(`Compiling ${flavor} ${buildType} apk`);

const capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1);

const runGradle = async (args) => {
console.log(chalk.yellow('Running', `gradle ${args[0]}`));
logger.debug(`Running gradle ${args[0]}`);

await new Promise((resolve, reject) => {
const gradleProcess = childProcess.execFile(
Expand All @@ -318,7 +313,9 @@ class PlatformAndroid extends AbstractPlatform {
(error) => error ? reject(error) : resolve()
);

gradleProcess.stdout.pipe(process.stdout);
if (zbLogger.levels[logger.level] >= zbLogger.levels.verbose) {
gradleProcess.stdout.pipe(process.stdout);
}
gradleProcess.stderr.pipe(process.stderr);
});
};
Expand All @@ -331,7 +328,7 @@ class PlatformAndroid extends AbstractPlatform {
* @param {Object} config
* @param {string} buildDir
* @param {string} distDir
* @return {Promise}
* @return {Promise<string>}
* @protected
*/
async _copyApk(config, buildDir, distDir) {
Expand All @@ -355,8 +352,10 @@ class PlatformAndroid extends AbstractPlatform {

if (config.storeRelease && await fse.exists(releaseBuild)) {
await fse.copy(releaseBuild, releaseTarget);
return releaseTarget;
} else if (await fse.exists(debugBuild)) {
await fse.copy(debugBuild, debugTarget);
return debugTarget;
}
}
}
Expand Down
66 changes: 33 additions & 33 deletions lib/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
import AbstractInput from 'zb/device/abstract-input';
import UnsupportedFeature from 'zb/device/errors/unsupported-feature';
import Keys from 'zb/device/input/keys';
import Key from 'zb/device/input/key';
import Info from './info';


Expand Down Expand Up @@ -105,12 +105,12 @@ export default class Input extends AbstractInput {
_createKeysMap() {
const map = {};

map[37] = Keys.LEFT;
map[38] = Keys.UP;
map[39] = Keys.RIGHT;
map[40] = Keys.DOWN;
map[37] = Key.LEFT;
map[38] = Key.UP;
map[39] = Key.RIGHT;
map[40] = Key.DOWN;

map[13] = Keys.ENTER;
map[13] = Key.ENTER;

return map;
}
Expand All @@ -122,20 +122,20 @@ export default class Input extends AbstractInput {
if (this._info.isSonyBravia()) {
switch (event.key) {
case 'ColorF0Red':
return Keys.RED;
return Key.RED;
case 'ColorF1Green':
return Keys.GREEN;
return Key.GREEN;
case 'ColorF2Yellow':
return Keys.YELLOW;
return Key.YELLOW;
case 'ColorF3Blue':
return Keys.BLUE;
return Key.BLUE;

case 'Info':
return Keys.INFO;
return Key.INFO;
case 'MediaPlay':
return Keys.PLAY;
return Key.PLAY;
case 'MediaPlayPause':
return Keys.PAUSE;
return Key.PAUSE;
}
}

Expand All @@ -148,37 +148,37 @@ export default class Input extends AbstractInput {
_createKeysMapForSonyBravia() {
const zero = 48;

this._map[zero + 0] = Keys.DIGIT_0;
this._map[zero + 1] = Keys.DIGIT_1;
this._map[zero + 2] = Keys.DIGIT_2;
this._map[zero + 3] = Keys.DIGIT_3;
this._map[zero + 4] = Keys.DIGIT_4;
this._map[zero + 5] = Keys.DIGIT_5;
this._map[zero + 6] = Keys.DIGIT_6;
this._map[zero + 7] = Keys.DIGIT_7;
this._map[zero + 8] = Keys.DIGIT_8;
this._map[zero + 9] = Keys.DIGIT_9;
this._map[zero + 0] = Key.DIGIT_0;
this._map[zero + 1] = Key.DIGIT_1;
this._map[zero + 2] = Key.DIGIT_2;
this._map[zero + 3] = Key.DIGIT_3;
this._map[zero + 4] = Key.DIGIT_4;
this._map[zero + 5] = Key.DIGIT_5;
this._map[zero + 6] = Key.DIGIT_6;
this._map[zero + 7] = Key.DIGIT_7;
this._map[zero + 8] = Key.DIGIT_8;
this._map[zero + 9] = Key.DIGIT_9;

this._map[33] = Keys.PAGE_UP;
this._map[34] = Keys.PAGE_DOWN;
this._map[33] = Key.PAGE_UP;
this._map[34] = Key.PAGE_DOWN;

// Bravia 2015 has separate Play and Pause keys, but they have the same keycode.
// They can be identified by key property in _keyboardEventToKeyCode
this._map[179] = Keys.PLAY_PAUSE;
this._map[179] = Key.PLAY_PAUSE;

this._map[178] = Keys.STOP;
this._map[227] = Keys.REW;
this._map[228] = Keys.FWD;
this._map[176] = Keys.NEXT_CHAPTER;
this._map[177] = Keys.PREV_CHAPTER;
this._map[178] = Key.STOP;
this._map[227] = Key.REW;
this._map[228] = Key.FWD;
this._map[176] = Key.NEXT_CHAPTER;
this._map[177] = Key.PREV_CHAPTER;

this._map[27] = Keys.EXIT;
this._map[27] = Key.EXIT;
}

/**
* @private
*/
_createKeysMapForNexus() {
this._map[179] = Keys.PLAY_PAUSE;
this._map[179] = Key.PLAY_PAUSE;
}
}
Loading

0 comments on commit 540a210

Please sign in to comment.