mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 15:58:39 +09:00
pt 1 in reviving the android build (copied from pm 28a1, wish me luck)
This commit is contained in:
parent
efa9662725
commit
d7788a6d6d
4249 changed files with 468189 additions and 0 deletions
|
|
@ -0,0 +1,52 @@
|
|||
package org.mozilla.gecko.adjust;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.mozilla.gecko.AdjustConstants;
|
||||
import org.mozilla.gecko.BrowserApp;
|
||||
import org.mozilla.gecko.GeckoSharedPrefs;
|
||||
import org.mozilla.gecko.delegates.BrowserAppDelegate;
|
||||
import org.mozilla.gecko.mozglue.SafeIntent;
|
||||
import org.mozilla.gecko.preferences.GeckoPreferences;
|
||||
import org.mozilla.gecko.util.IntentUtils;
|
||||
|
||||
public class AdjustBrowserAppDelegate extends BrowserAppDelegate {
|
||||
private final AdjustHelperInterface adjustHelper;
|
||||
private final AttributionHelperListener attributionHelperListener;
|
||||
|
||||
public AdjustBrowserAppDelegate(AttributionHelperListener attributionHelperListener) {
|
||||
this.adjustHelper = AdjustConstants.getAdjustHelper();
|
||||
this.attributionHelperListener = attributionHelperListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(BrowserApp browserApp, Bundle savedInstanceState) {
|
||||
adjustHelper.onCreate(browserApp,
|
||||
AdjustConstants.MOZ_INSTALL_TRACKING_ADJUST_SDK_APP_TOKEN,
|
||||
attributionHelperListener);
|
||||
|
||||
final boolean isInAutomation = IntentUtils.getIsInAutomationFromEnvironment(
|
||||
new SafeIntent(browserApp.getIntent()));
|
||||
|
||||
final SharedPreferences prefs = GeckoSharedPrefs.forApp(browserApp);
|
||||
|
||||
// Adjust stores enabled state so this is only necessary because users may have set
|
||||
// their data preferences before this feature was implemented and we need to respect
|
||||
// those before upload can occur in Adjust.onResume.
|
||||
adjustHelper.setEnabled(!isInAutomation
|
||||
&& prefs.getBoolean(GeckoPreferences.PREFS_HEALTHREPORT_UPLOAD_ENABLED, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(BrowserApp browserApp) {
|
||||
// Needed for Adjust to get accurate session measurements
|
||||
adjustHelper.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause(BrowserApp browserApp) {
|
||||
// Needed for Adjust to get accurate session measurements
|
||||
adjustHelper.onPause();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko.adjust;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.adjust.sdk.Adjust;
|
||||
import com.adjust.sdk.AdjustAttribution;
|
||||
import com.adjust.sdk.AdjustConfig;
|
||||
import com.adjust.sdk.AdjustReferrerReceiver;
|
||||
import com.adjust.sdk.LogLevel;
|
||||
import com.adjust.sdk.OnAttributionChangedListener;
|
||||
|
||||
import org.mozilla.gecko.AppConstants;
|
||||
|
||||
public class AdjustHelper implements AdjustHelperInterface, OnAttributionChangedListener {
|
||||
|
||||
private static final String LOGTAG = AdjustHelper.class.getSimpleName();
|
||||
private AttributionHelperListener attributionListener;
|
||||
|
||||
public void onCreate(final Context context, final String maybeAppToken, final AttributionHelperListener listener) {
|
||||
final String environment;
|
||||
final LogLevel logLevel;
|
||||
if (AppConstants.MOZILLA_OFFICIAL) {
|
||||
environment = AdjustConfig.ENVIRONMENT_PRODUCTION;
|
||||
logLevel = LogLevel.WARN;
|
||||
} else {
|
||||
environment = AdjustConfig.ENVIRONMENT_SANDBOX;
|
||||
logLevel = LogLevel.VERBOSE;
|
||||
}
|
||||
if (maybeAppToken == null) {
|
||||
// We've got install tracking turned on -- we better have a token!
|
||||
throw new IllegalArgumentException("maybeAppToken must not be null");
|
||||
}
|
||||
attributionListener = listener;
|
||||
AdjustConfig config = new AdjustConfig(context, maybeAppToken, environment);
|
||||
config.setLogLevel(logLevel);
|
||||
config.setOnAttributionChangedListener(this);
|
||||
Adjust.onCreate(config);
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
Adjust.onPause();
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
Adjust.onResume();
|
||||
}
|
||||
|
||||
public void setEnabled(final boolean isEnabled) {
|
||||
Adjust.setEnabled(isEnabled);
|
||||
}
|
||||
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
new AdjustReferrerReceiver().onReceive(context, intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttributionChanged(AdjustAttribution attribution) {
|
||||
if (attributionListener == null) {
|
||||
throw new IllegalStateException("Expected non-null attribution listener.");
|
||||
}
|
||||
|
||||
if (attribution == null) {
|
||||
Log.e(LOGTAG, "Adjust attribution is null; skipping campaign id retrieval.");
|
||||
return;
|
||||
}
|
||||
attributionListener.onCampaignIdChanged(attribution.campaign);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko.adjust;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
public interface AdjustHelperInterface {
|
||||
/**
|
||||
* Register the Application with the Adjust SDK.
|
||||
* @param appToken the (secret!) Adjust SDK per-application token to register with; may be null.
|
||||
*/
|
||||
void onCreate(final Context context, final String appToken, final AttributionHelperListener listener);
|
||||
void onPause();
|
||||
void onResume();
|
||||
|
||||
void setEnabled(final boolean isEnabled);
|
||||
void onReceive(final Context context, final Intent intent);
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko.adjust;
|
||||
|
||||
/**
|
||||
* Because of how our build module dependencies are structured, we aren't able to use
|
||||
* the {@link com.adjust.sdk.OnAttributionChangedListener} directly outside of {@link AdjustHelper}.
|
||||
* If the Adjust SDK is enabled, this listener should be notified when {@link com.adjust.sdk.OnAttributionChangedListener}
|
||||
* is fired (i.e. this listener would be daisy-chained to the Adjust one). The listener also
|
||||
* inherits thread-safety from GeckoSharedPrefs which is used to store the campaign ID.
|
||||
*/
|
||||
public interface AttributionHelperListener {
|
||||
void onCampaignIdChanged(String campaignId);
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko.adjust;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
public class StubAdjustHelper implements AdjustHelperInterface {
|
||||
public void onCreate(final Context context, final String appToken, final AttributionHelperListener listener) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
public void setEnabled(final boolean isEnabled) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue