Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-26094
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Jun 5, 2018
2 parents 33ca96c + ec63001 commit 6051e7d
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 45 deletions.
2 changes: 1 addition & 1 deletion android/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,6 @@ AndroidBuilder.prototype.doAnalytics = function doAnalytics(next) {
}

cli.addAnalyticsEvent(eventName, {
dir: cli.argv['project-dir'],
name: cli.tiapp.name,
publisher: cli.tiapp.publisher,
url: cli.tiapp.url,
Expand Down Expand Up @@ -3848,6 +3847,7 @@ AndroidBuilder.prototype.generateAndroidManifest = function generateAndroidManif
finalAndroidManifest.application.service || (finalAndroidManifest.application.service = {});
finalAndroidManifest.application.service[tiAnalyticsService] = {
name: tiAnalyticsService,
permission: 'android.permission.BIND_JOB_SERVICE',
exported: false
};
}
Expand Down
23 changes: 11 additions & 12 deletions android/cli/commands/_buildModule.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* Android module build command.
*
* @module cli/_buildModule
*
* @copyright
* Copyright (c) 2014-2017 by Appcelerator, Inc. All Rights Reserved.
*
* @license
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
* Android module build command.
*
* @module cli/_buildModule
*
* @copyright
* Copyright (c) 2014-2018 by Appcelerator, Inc. All Rights Reserved.
*
* @license
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

'use strict';

Expand Down Expand Up @@ -362,7 +362,6 @@ AndroidModuleBuilder.prototype.doAnalytics = function doAnalytics(next) {
eventName = 'android.' + cli.argv.type;

cli.addAnalyticsEvent(eventName, {
dir: cli.argv['project-dir'],
name: manifest.name,
publisher: manifest.author,
appid: manifest.moduleid,
Expand Down
2 changes: 1 addition & 1 deletion android/dev/TitaniumTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<activity android:name="ti.modules.titanium.ui.android.TiPreferencesActivity" android:configChanges="screenSize"/>
<activity android:name="ti.modules.titanium.media.TiCameraActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:theme="@style/Theme.AppCompat.Translucent.NoTitleBar.Fullscreen"/>
<provider android:name="org.appcelerator.titanium.io.TiFileProvider" android:authorities="com.titanium.test.tifileprovider" android:exported="false" android:grantUriPermissions="true"/>
<service android:name="com.appcelerator.aps.APSAnalyticsService" android:exported="false"/>
<service android:name="com.appcelerator.aps.APSAnalyticsService" android:permission="android.permission.BIND_JOB_SERVICE" android:exported="false"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public void onCreate() {
super.onCreate();

appInfo = new TitaniumTestAppInfo(this);
postAppInfo();

// KrollAssetHelper.setAssetCrypt(new AssetCryptImpl());
V8Runtime runtime = new V8Runtime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiPlatformHelper;
import org.json.JSONArray;
Expand Down Expand Up @@ -50,6 +51,24 @@ public AnalyticsModule()
super();
}

// clang-format off
@Kroll.method
@Kroll.getProperty
public boolean getOptedOut()
// clang-format on
{
return APSAnalytics.getInstance().isOptedOut();
}

// clang-format off
@Kroll.method
@Kroll.setProperty
public void setOptedOut(boolean optedOut)
// clang-format on
{
APSAnalytics.getInstance().setOptedOut(optedOut);
}

@Kroll.method
public void navEvent(String from, String to, @Kroll.argument(optional = true) String event,
@Kroll.argument(optional = true) KrollDict data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
import android.os.PowerManager;
Expand All @@ -36,6 +37,11 @@ public class NotificationManagerModule extends KrollModule
protected static final int PENDING_INTENT_FOR_BROADCAST = 2;
protected static final int PENDING_INTENT_MAX_VALUE = PENDING_INTENT_FOR_SERVICE;

private static NotificationManager notificationManager = null;
private static NotificationChannel defaultChannel = null;

public static final String DEFAULT_CHANNEL_ID = "ti_default_channel";

@Kroll.constant
public static final int DEFAULT_ALL = Notification.DEFAULT_ALL;
@Kroll.constant
Expand Down Expand Up @@ -73,9 +79,33 @@ public NotificationProxy createNotification(Object[] args)
return notification;
}

private NotificationManager getManager()
public static NotificationManager getManager()
{
return (NotificationManager) TiApplication.getInstance().getSystemService(Activity.NOTIFICATION_SERVICE);
if (notificationManager == null) {
notificationManager =
(NotificationManager) TiApplication.getInstance().getSystemService(Activity.NOTIFICATION_SERVICE);
}
return notificationManager;
}

public static boolean useDefaultChannel()
{
// use default channel if we are targeting API 26+
boolean useDefaultChannel =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& TiApplication.getInstance().getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O;

// setup default channel it it does not exist
if (useDefaultChannel && defaultChannel == null) {
defaultChannel =
new NotificationChannel(DEFAULT_CHANNEL_ID, "miscellaneous", NotificationManager.IMPORTANCE_DEFAULT);
getManager().createNotificationChannel(defaultChannel);
Log.w(
TAG,
"Falling back to default notification channel.\nIt is highly advised to create your own notification channel using Ti.Android.NotificationManager.createNotificationChannel()");
}

return useDefaultChannel;
}

@TargetApi(26)
Expand Down Expand Up @@ -106,7 +136,14 @@ public void cancelAll()
@Kroll.method
public void notify(int id, NotificationProxy notificationProxy)
{
getManager().notify(id, notificationProxy.buildNotification());
Notification notification = notificationProxy.buildNotification();

// targeting Android O or above? create default channel
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && notification.getChannelId() == DEFAULT_CHANNEL_ID) {
useDefaultChannel();
}

getManager().notify(id, notification);

HashMap wakeParams = notificationProxy.getWakeParams();
if (wakeParams != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public NotificationProxy()
super();
notificationBuilder = new NotificationCompat.Builder(TiApplication.getInstance().getApplicationContext())
.setSmallIcon(android.R.drawable.stat_sys_warning)
.setWhen(System.currentTimeMillis());
.setWhen(System.currentTimeMillis())
.setChannelId(NotificationManagerModule.useDefaultChannel()
? NotificationManagerModule.DEFAULT_CHANNEL_ID
: "miscellaneous"); // NotificationChannel.DEFAULT_CHANNEL_ID

//set up default values
flags = Notification.FLAG_AUTO_CANCEL;
Expand Down
Binary file modified android/titanium/lib/aps-analytics.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ public void uncaughtException(Thread t, Throwable e)
proxyMap = new HashMap<String, SoftReference<KrollProxy>>(5);

tempFileHelper = new TiTempFileHelper(this);

deployData = new TiDeployData(this);
}

@Override
Expand Down Expand Up @@ -426,14 +428,9 @@ public void onTrimMemory(int level)

public void postAppInfo()
{
deployData = new TiDeployData(this);

TiPlatformHelper.getInstance().initialize();
// Fastdev has been deprecated
// TiFastDev.initFastDev(this);

if (isAnalyticsEnabled()) {

TiPlatformHelper.getInstance().initialize();
TiPlatformHelper.getInstance().initAnalytics();
TiPlatformHelper.getInstance().setSdkVersion("ti." + getTiBuildVersion());
TiPlatformHelper.getInstance().setAppName(getAppInfo().getName());
Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,11 @@ public class TiC
*/
public static final String PROPERTY_OPTIONS = "options";

/**
* @module.api
*/
public static final String PROPERTY_OPTED_OUT = "optedOut";

/**
* @module.api
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.appcelerator.kroll.util.KrollAssetHelper;
import org.appcelerator.titanium.proxy.IntentProxy;
import org.appcelerator.titanium.util.TiColorHelper;
import org.appcelerator.titanium.util.TiPlatformHelper;
import org.appcelerator.titanium.util.TiUrl;
import org.appcelerator.titanium.view.TiCompositeLayout;

Expand Down Expand Up @@ -188,6 +189,7 @@ protected void windowCreated(Bundle savedInstanceState)
super.windowCreated(savedInstanceState);
loadActivityScript();
scriptLoaded();
TiApplication.getInstance().postAppInfo();
}

protected boolean checkInvalidLaunch(Bundle savedInstanceState)
Expand Down
3 changes: 1 addition & 2 deletions cli/lib/creators/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Logic for creating new Titanium apps.
*
* @copyright
* Copyright (c) 2014-2015 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2014-2018 by Appcelerator, Inc. All Rights Reserved.
*
* @license
* Licensed under the terms of the Apache Public License
Expand Down Expand Up @@ -209,7 +209,6 @@ AppCreator.prototype.run = function run(callback) {
tasks.push(function (next) {
// send the analytics
this.cli.addAnalyticsEvent('project.create.mobile', {
dir: projectDir,
name: argv.name,
publisher: projectConfig.publisher,
url: projectConfig.url,
Expand Down
3 changes: 1 addition & 2 deletions cli/lib/creators/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Logic for creating new Titanium modules.
*
* @copyright
* Copyright (c) 2014-2017 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2014-2018 by Appcelerator, Inc. All Rights Reserved.
*
* @license
* Licensed under the terms of the Apache Public License
Expand Down Expand Up @@ -192,7 +192,6 @@ ModuleCreator.prototype.run = function run(callback) {
tasks.push(function (next) {
// send the analytics
this.cli.addAnalyticsEvent('project.create.module', {
dir: projectDir,
name: variables.moduleName,
author: variables.author,
moduleid: variables.moduleId,
Expand Down
Binary file modified iphone/Classes/APSAnalytics/libAPSAnalytics.a
Binary file not shown.
2 changes: 0 additions & 2 deletions iphone/Classes/TiErrorController.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,13 @@ - (void)loadView

[self.view layoutIfNeeded];

#if IS_XCODE_8
// use haptic feedback on supported devices
if ([TiUtils isIOSVersionOrGreater:@"10.0"]) {
UINotificationFeedbackGenerator *generator = [UINotificationFeedbackGenerator new];
[generator prepare];
[generator notificationOccurred:UINotificationFeedbackTypeError];
RELEASE_TO_NIL(generator);
}
#endif
}

- (BOOL)prefersHomeIndicatorAutoHidden
Expand Down
3 changes: 1 addition & 2 deletions iphone/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @module cli/_build
*
* @copyright
* Copyright (c) 2009-2017 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2018 by Appcelerator, Inc. All Rights Reserved.
*
* @license
* Licensed under the terms of the Apache Public License
Expand Down Expand Up @@ -2329,7 +2329,6 @@ iOSBuilder.prototype.doAnalytics = function doAnalytics() {
}

cli.addAnalyticsEvent(eventName, {
dir: cli.argv['project-dir'],
name: this.tiapp.name,
publisher: this.tiapp.publisher,
url: this.tiapp.url,
Expand Down
23 changes: 11 additions & 12 deletions iphone/cli/commands/_buildModule.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* iOS module build command.
*
* @module cli/_buildModule
*
* @copyright
* Copyright (c) 2014-2017 by Appcelerator, Inc. All Rights Reserved.
*
* @license
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
* iOS module build command.
*
* @module cli/_buildModule
*
* @copyright
* Copyright (c) 2014-2018 by Appcelerator, Inc. All Rights Reserved.
*
* @license
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/

'use strict';

Expand Down Expand Up @@ -126,7 +126,6 @@ iOSModuleBuilder.prototype.doAnalytics = function doAnalytics() {
eventName = 'ios.' + cli.argv.type;

cli.addAnalyticsEvent(eventName, {
dir: this.cli.argv['project-dir'],
name: this.moduleName,
publisher: this.manifest.author,
appid: this.moduleId,
Expand Down

0 comments on commit 6051e7d

Please sign in to comment.