Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(android): changed minSdkVersion to 21 (Android 5.0) #12316

Merged
merged 15 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,15 @@ def gatherAndroidCrashReports() {
}
}

def androidUnitTests(nodeVersion, npmVersion, testOnDevices) {
def androidUnitTests(testName, nodeVersion, npmVersion, testOnDevices, deviceId) {
return {
def labels = 'git && osx && android-emulator && android-sdk' // FIXME get working on windows/linux!
if (testOnDevices) {
labels += ' && macos-rocket' // run main branch tests on devices, use node with devices connected
}
if (!deviceId) {
deviceId = testOnDevices ? 'all' : 'android-30-playstore-x86';
}

node(labels) {
// TODO: Do a shallow checkout rather than stash/unstash?
Expand All @@ -108,10 +111,10 @@ def androidUnitTests(nodeVersion, npmVersion, testOnDevices) {
sh returnStatus: true, script: 'ti config android.buildTools.selectedVersion --remove'
// run main branch tests on devices
if (testOnDevices) {
sh label: 'Run Test Suite on device(s)', script: "npm run test:integration -- android -T device -C all"
sh label: 'Run Test Suite on device(s)', script: "npm run test:integration -- android -T device -C ${deviceId}"
// run PR tests on emulator
} else {
sh label: 'Run Test Suite on emulator', script: "npm run test:integration -- android -T emulator -D test -C android-30-playstore-x86"
sh label: 'Run Test Suite on emulator', script: "npm run test:integration -- android -T emulator -D test -C ${deviceId}"
}
} // timeout
}
Expand All @@ -133,7 +136,7 @@ def androidUnitTests(nodeVersion, npmVersion, testOnDevices) {
}
} // try/catch/finally
// save the junit reports as artifacts explicitly so danger.js can use them later
stash includes: 'junit.*.xml', name: 'test-report-android'
stash includes: 'junit.*.xml', name: "test-report-android-${testName}"
junit 'junit.*.xml'
archiveArtifacts allowEmptyArchive: true, artifacts: 'tests/diffs/,tests/generated/'
} // nodejs
Expand Down Expand Up @@ -373,7 +376,8 @@ timestamps {
// Run unit tests in parallel for android/iOS
stage('Test') {
parallel(
'android unit tests': androidUnitTests(nodeVersion, npmVersion, testOnDevices),
'android main unit tests': androidUnitTests('main', nodeVersion, npmVersion, testOnDevices, null),
'android 5.0 unit tests': androidUnitTests('5.0', nodeVersion, npmVersion, false, 'android-21-x86'),
'iPhone unit tests': iosUnitTests('iphone', nodeVersion, npmVersion, testOnDevices),
'iPad unit tests': iosUnitTests('ipad', nodeVersion, npmVersion, testOnDevices),
'macOS unit tests': macosUnitTests(nodeVersion, npmVersion),
Expand Down Expand Up @@ -538,7 +542,7 @@ timestamps {
} catch (e) {}

// it's ok to not grab all test results, still run Danger.JS (even if some platforms crashed or we failed before tests)
def reports = [ 'ios-ipad', 'ios-iphone', 'ios-macos', 'android', 'cli' ]
def reports = [ 'ios-ipad', 'ios-iphone', 'ios-macos', 'android-main', 'android-5.0', 'cli' ]
for (int i = 0; i < reports.size(); i++) {
try {
unstash "test-report-${reports[i]}"
Expand Down
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
compileSdkVersion 30
defaultConfig {
applicationId 'com.titanium.test'
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName '1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@ public void setLargeIcon(Object icon)
@Kroll.setProperty
public void setColor(String color)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
notificationBuilder.setColor(TiColorHelper.parseColor(color));
}
notificationBuilder.setColor(TiColorHelper.parseColor(color));
setProperty(TiC.PROPERTY_COLOR, color);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Build;
import android.provider.Settings;
import androidx.core.view.accessibility.AccessibilityEventCompat;
import androidx.core.view.accessibility.AccessibilityManagerCompat;
import androidx.core.view.accessibility.AccessibilityManagerCompat.AccessibilityStateChangeListenerCompat;
Expand Down Expand Up @@ -166,22 +164,7 @@ public String appURLToPath(String url)
@Kroll.getProperty
public boolean getAccessibilityEnabled()
{
AccessibilityManager manager = TiApplication.getInstance().getAccessibilityManager();
boolean enabled = manager.isEnabled();

if (!enabled && Build.VERSION.SDK_INT < TiC.API_LEVEL_HONEYCOMB) {
// Prior to Honeycomb, AccessibilityManager.isEnabled() would sometimes
// return false erroneously the because manager service would asynchronously set the
// enabled property in the manager client. So when checking the value, it
// might not have been set yet. In studying the changes they made for
// Honeycomb, we can see that they do the following in order to determine
// if accessibility really is enabled or not:
enabled = Settings.Secure.getInt(TiApplication.getInstance().getContentResolver(),
Settings.Secure.ACCESSIBILITY_ENABLED, 0)
== 1;
}

return enabled;
return TiApplication.getInstance().getAccessibilityManager().isEnabled();
}

@Kroll.method(name = "_restart")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import android.Manifest;
import android.app.Activity;
import android.os.Build;

@Kroll.module
public class CalendarModule extends KrollModule
Expand Down Expand Up @@ -162,20 +161,9 @@ public CalendarProxy[] getAllCalendars()
@Kroll.getProperty
public CalendarProxy[] getSelectableCalendars()
{
ArrayList<CalendarProxy> calendars;
// selectable calendars are "visible"
if (Build.VERSION.SDK_INT >= 14) { // ICE_CREAM_SANDWICH, 4.0
calendars = CalendarProxy.queryCalendars("Calendars.visible = ?", new String[] { "1" });
}
// selectable calendars are "selected"
else if (Build.VERSION.SDK_INT >= 11) { // HONEYCOMB, 3.0
calendars = CalendarProxy.queryCalendars("Calendars.selected = ?", new String[] { "1" });
}
// selectable calendars are "selected" && !"hidden"
else {
calendars = CalendarProxy.queryCalendars("Calendars.selected = ? AND Calendars.hidden = ?",
new String[] { "1", "0" });
}
ArrayList<CalendarProxy> calendars;
calendars = CalendarProxy.queryCalendars("Calendars.visible = ?", new String[] { "1" });
return calendars.toArray(new CalendarProxy[calendars.size()]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ public CalendarProxy(String id, String name, boolean selected, boolean hidden)

public static String getBaseCalendarUri()
{
if (Build.VERSION.SDK_INT >= 8) { // FROYO, 2.2
return "content://com.android.calendar";
}

return "content://calendar";
return "content://com.android.calendar";
}

public static ArrayList<CalendarProxy> queryCalendars(String query, String[] queryArgs)
Expand All @@ -61,32 +57,20 @@ public static ArrayList<CalendarProxy> queryCalendars(String query, String[] que
}
ContentResolver contentResolver = TiApplication.getInstance().getContentResolver();

Cursor cursor = null;
if (Build.VERSION.SDK_INT >= 14) { // ICE_CREAM_SANDWICH, 4.0
cursor = contentResolver.query(Uri.parse(getBaseCalendarUri() + "/calendars"),
new String[] { "_id", "calendar_displayName", "visible" }, query, queryArgs,
null);
} else if (Build.VERSION.SDK_INT >= 11) { // HONEYCOMB, 3.0
cursor = contentResolver.query(Uri.parse(getBaseCalendarUri() + "/calendars"),
new String[] { "_id", "displayName", "selected" }, query, queryArgs, null);
} else {
cursor = contentResolver.query(Uri.parse(getBaseCalendarUri() + "/calendars"),
new String[] { "_id", "displayName", "selected", "hidden" }, query,
queryArgs, null);
}
Cursor cursor = contentResolver.query(
Uri.parse(getBaseCalendarUri() + "/calendars"),
new String[] { "_id", "calendar_displayName", "visible" },
query,
queryArgs,
null);

// calendars can be null
if (cursor != null) {
while (cursor.moveToNext()) {
String id = cursor.getString(0);
String name = cursor.getString(1);
boolean selected = !cursor.getString(2).equals("0");
// For API level >= 11 (3.0), there is no column "hidden".
boolean hidden = false;
if (Build.VERSION.SDK_INT < 11) {
hidden = !cursor.getString(3).equals("0");
}

calendars.add(new CalendarProxy(id, name, selected, hidden));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.CalendarContract.Events;
import android.provider.CalendarContract.Instances;

Expand Down Expand Up @@ -91,18 +90,16 @@ public static ArrayList<EventProxy> queryEventsBetweenDates(long date1, long dat
ContentUris.appendId(builder, date1);
ContentUris.appendId(builder, date2);

String visibility = "";
if (Build.VERSION.SDK_INT >= 14) {
visibility = Instances.ACCESS_LEVEL;
} else {
visibility = "visibility";
}

Cursor eventCursor = contentResolver.query(builder.build(),
new String[] { "event_id", "title", "description", "eventLocation",
"begin", "end", "allDay", "hasAlarm", "eventStatus",
visibility, Events.RRULE, Events.CALENDAR_ID },
query, queryArgs, "startDay ASC, startMinute ASC");
Cursor eventCursor = contentResolver.query(
builder.build(),
new String[] {
"event_id", "title", "description", "eventLocation",
"begin", "end", "allDay", "hasAlarm", "eventStatus",
Instances.ACCESS_LEVEL, Events.RRULE, Events.CALENDAR_ID
},
query,
queryArgs,
"startDay ASC, startMinute ASC");

if (eventCursor == null) {
Log.w(TAG, "Unable to get any results when pulling events by date range");
Expand Down Expand Up @@ -164,18 +161,11 @@ public static ArrayList<EventProxy> queryEvents(Uri uri, String query, String[]
}
ContentResolver contentResolver = TiApplication.getInstance().getContentResolver();

String visibility = "";
if (Build.VERSION.SDK_INT >= 14) {
visibility = Instances.ACCESS_LEVEL;
} else {
visibility = "visibility";
}

Cursor eventCursor = contentResolver.query(
uri,
new String[] {
"_id", "title", "description", "eventLocation", "dtstart", "dtend", "allDay", "hasAlarm",
"eventStatus", visibility, Events.RRULE, Events.CALENDAR_ID, "hasExtendedProperties"
"eventStatus", Instances.ACCESS_LEVEL, Events.RRULE, Events.CALENDAR_ID, "hasExtendedProperties"
},
query, queryArgs, orderBy);

Expand Down Expand Up @@ -228,11 +218,7 @@ public static EventProxy createEvent(CalendarProxy calendar, KrollDict data)
event.title = TiConvert.toString(data, "title");
eventValues.put("title", event.title);
eventValues.put("calendar_id", calendar.getId());

// ICS requires eventTimeZone field when inserting new event
if (Build.VERSION.SDK_INT >= 14) {
eventValues.put(Events.EVENT_TIMEZONE, new Date().toString());
}
eventValues.put(Events.EVENT_TIMEZONE, new Date().toString());

if (data.containsKey(TiC.PROPERTY_LOCATION)) {
event.location = TiConvert.toString(data, TiC.PROPERTY_LOCATION);
Expand Down Expand Up @@ -280,11 +266,7 @@ public static EventProxy createEvent(CalendarProxy calendar, KrollDict data)

public static ArrayList<EventProxy> queryEventsBetweenDates(long date1, long date2, CalendarProxy calendar)
{
if (Build.VERSION.SDK_INT >= 11) {
return queryEventsBetweenDates(date1, date2, "calendar_id=" + calendar.getId(), null);
} else {
return queryEventsBetweenDates(date1, date2, "Calendars._id=" + calendar.getId(), null);
}
return queryEventsBetweenDates(date1, date2, "calendar_id=" + calendar.getId(), null);
}

private Object setValueFromCursorForColumn(Cursor cursor, String columnName, Object defaultValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,18 @@

public abstract class CommonContactsApi
{
private static final boolean TRY_NEWER_API =
(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT);
private static final String TAG = "TiCommonContactsApi";

protected static CommonContactsApi getInstance()
{
boolean useNew = false;
if (TRY_NEWER_API) {
try {
Class.forName("android.provider.ContactsContract"); // just a test for success
useNew = true;

} catch (ClassNotFoundException e) {
Log.e(TAG, "Unable to load contacts api: " + e.getMessage(), e);
useNew = false;
}
} else {
Log.e(TAG, "Contacts API 4 is not supported");
try {
Class.forName("android.provider.ContactsContract"); // just a test for success
useNew = true;

} catch (ClassNotFoundException e) {
Log.e(TAG, "Unable to load contacts api: " + e.getMessage(), e);
useNew = false;
}

if (useNew) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import android.database.AbstractWindowedCursor;
import android.database.Cursor;
import android.database.SQLException;
import android.os.Build;

@Kroll.proxy(parentModule = DatabaseModule.class)
public class TiResultSetProxy extends KrollProxy
Expand Down Expand Up @@ -122,11 +121,7 @@ private Object internalGetField(int index, int type)
if (fromString) {
result = rs.getString(index);
}
if (outOfBounds && Build.VERSION.SDK_INT >= 11) {
// TIMOB-4515: Column number doesn't exist, yet no exception
// occurred. This is known to happen in Honeycomb. So
// we'll throw instead. We throw the same exception type that
// Android would.
if (outOfBounds) {
throw new IllegalStateException("Requested column number " + index + " does not exist");
}
} catch (RuntimeException e) {
Expand Down